Pretty CSS URLs (easycaching?) on 1.6.3 and lighttpd with a 4 lines patch

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
Pierre M.

Pretty CSS URLs (easycaching?) on 1.6.3 and lighttpd with a 4 lines patch

Post by Pierre M. »

Hello all,

I'd like to share this tip on how to make pretty CSS URLs, not only regular page.html pretty URL.

It requires a tiny patch. Hence no support if you use it. See http://forum.cmsmadesimple.org/index.ph ... 132.0.html
And it has not been much tested. And it may break something. You have been warned : no support neither about this hack nor for your contaminated CMSms installs.

Background : I like pretty URLs very much because they are end user friendly and web ecosystem compliant (proxy, cache, replication...) Hopefully CMSms has a pretty URLs feature for pages. It still relies on /stylesheet.php?this=that to broadcast CSS to the web. I'm proposing to make CSS URLs pretty too.

config.php extract :

Code: Select all

$config['url_rewriting'] = 'mod_rewrite';
$config['page_extension'] = '.html';
$config['use_hierarchy'] = true;
$config['query_var'] = 'page';
Nothing funky actually :-)

mod_rewrite extract :

Code: Select all

server.modules = ( "mod_this", "mod_that", "mod_rewrite" )

var.mydir = "/my/root/path/"
url.rewrite = (
var.mydir + "(.+)\.html" => var.mydir + "index.php?page=$1",
var.mydir + "(.+)\-(.+)\.css" => var.mydir + "stylesheet.php?cssid=$2&mediatype=$1"
)
It is a lighttpd quick and dirty example (1 line for .html and 1 line for .css) but it would be the same with Apache (htaccess).

The patch in plugins: diff 1.6.3-function.stylesheet.php new-function.stylesheet.php

Code: Select all

29,30c29,30
<     //if( $config['url_rewriting'] != 'none' )
<     if( 0 )
---
>     if( $config['url_rewriting'] == 'mod_rewrite' )
>     //if( 0 )
32c32
< 	$url = $config['root_url'].'/stylesheet.php/'.$cssid;
---
> 	$url = $config['root_url'];
35c35
< 	    $url .= '/'.$media;
---
> 	    $url .= '/'.$media.'-';
36a37
> 	$url .= $cssid.'.css';
Result : now the {stylesheet} plugin's output looks like this :

Code: Select all

<link rel="stylesheet" type="text/css" media="handheld" href="http://server.tld/my/root/path/handheld-41.css" />
which is compatible with CSS /my/root/path/image(upload...)

Presumed issue : the "media" field is required. But it doesn't hurt the web to provide it.

Hope you like this hack.
If you want to talk about lighttpd please start another thread. This one is about pretty CSS URLs.
Have fun with CMSms.

Pierre M.
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Pretty CSS URLs (easycaching?) on 1.6.3 and lighttpd with a 4 lines patch

Post by blast2007 »

You can obtain a better result (IMHO) using static_stylesheet plugin without any patch.
It gives you Pretty URL CSS  and it speeds up page loading.

regards
blast
Pierre M.

Re: Pretty CSS URLs (easycaching?) on 1.6.3 and lighttpd with a 4 lines patch

Post by Pierre M. »

Hi blast2007,

thank you for the feedback. I appreciate it.

And thank you for pointing me to static-css because :
-it aims to solve the same issue (pretty CSS URLs),
-it does it a very similar way (reworking the function.stylesheet.php plugin).

Let me elaborate more on my tip vs static-css :

I think "patch" is a matter of wording :
-I'm claiming a 4 lines *patch* in order to break support to avoid the DevTeam be disturbed by my patch users.
-static-css rewrite somewhat 40% of the *same* file, not only 4 lines. It is not strictly a patch but it is far more intrusive. And if the user isn't using mod_rewrite my "code" is a no-op (no side effect).

I don't understand what makes you think of "better result" with static-css. How to measure the result ?
As shown the 4 lines output href="http://server.tld/my/root/path/handheld-41.css is compatible with CSS /my/root/path/image(upload...) it "just works" where static-css fails (bug #2011 duplicated by feature request #2096).

BTW my patch-tip is against 1.6.3 ("mod_rewrite" in config.php) and static-css doesn't seem to respond to bug reports since 2007.

Feedback welcome, best wishes

Pierre M.
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Pretty CSS URLs (easycaching?) on 1.6.3 and lighttpd with a 4 lines patch

Post by blast2007 »

Dear Pierre,

my post was only a suggestion.

I appreciate your work, because users can choose different ways to solve their problems.

I think (IMHO) it's more easy to tell to a CMSMS beginner who wants pretty urls for a CMSMS site:
- Download function.static_stylesheet.php file and put it in /plugins folder.
- Use {static_stylesheet} instead of {stylesheet} in your template.
- Upgrade without headaches.

I like also your solution, but maybe it could be better to create a new plugin (named for example new-function.stylesheet.php) without breaking vanilla code. So, in case of upgrading, site will continue to wok without problems if you forget to re-patch original file.

For what concerns bug #2011 my simple workaround was to put a "/" before image filename.

Thanks again for your work

regards
blast

P.S ...no, I'm not the brother of static_stylesheet author ;)
Pierre M.

Re: Pretty CSS URLs (easycaching?) on 1.6.3 and lighttpd with a 4 lines patch

Post by Pierre M. »

Thank you again for the feedback.

I have submitted it as feature request #3958 because (as far as I can figure) if these 4 lines were merged in core :
-no need to download a plugin,
-no need to change the templates,
-no need to change the stylesheets,
-no headaches while upgrading,
-I trust it ;-)

Pierre M.
Post Reply

Return to “Tips and Tricks”