March 04, 2004 | Category:

Gzip CSS

Using a very simple technique, it is possible to compress your CSS files with PHP.

Following the instructions on that site, and you can cut your CSS files by a large percentage. Good for bandwidth, good for visitors.

However, I would suggest one modification to the code given: do some user-agent sniffing for Netscape 4. Now, normally I’m not a fan of UA specific techniques, but if you don’t make an exception in this case, the GZip process will crash Netscape 4.

The problem is that it is difficult to target that particular browser. After some careful observation of various similar UA string, I think it is sufficient to not run the compression routine if you find the string Mozilla/4 but not the string compatible.

In addition, I’ve set up an htacess rule to parse .css files, rather than rename them to .php.