In my project CSS files can be pre-processed and then optionally minified (depending upon configuration).
Q1. Should multiple cache variations be generated for different combinations of CSS files?
res.php?stylesheets=test.css,test2.css,test3.css
res.php?stylesheets=test.css,test3.css
Q2. In the past I have noticed that such cache files were given some sort of GUID. How can I generate such an ID based upon the request?
res.php?stylesheets=test.css,test2.css,test3.css
=> cache/css/a3cadfeA33afADSFwwrzgnzzddsveraeAE
res.php?stylesheets=test.css,test3.css
=> cache/css/ergope4t5oiyk0sfb9x0fHkg04mm04tjzG
Please excuse the naivety of the above IDs!
Somehow I need to be able to regenerate the same ID from the stylesheets specified.
My question is only about caching of multiple variations and ID generation.
Yes, some pages will need different combinations of style sheets. Each combination must be cached individually. Unfortunately, the browser won’t know that there isn’t a difference between
?stylesheets=a.css,b.cssand?stylesheets=b.css,a.cssso both will need to be cached.That’s used to make sure the browser doesn’t accidentally cache the dynamically generated stylesheet. It’s unnecessary if you are using a decent minifier. Usually, the GUID is found by hashing the
last-modifiedtimes of each file in the list. Like I said, most minifiers will automatically check for new versions of files and discard the old cached version.I would suggest PHP Minify. Installation is as easy as copying the folder into your doc root. It also supports JavaScript compression with the Google Closure Compiler.