Compress your CSS
This article has been rendered obsolete by this newer article. Read it for updated and better code.
As all web developers know, CSS files can grow pretty big when building complex websites. Of course we can optimize the size of our CSS by using shorthands and cutting down on comments and whitespace but all of this goes at the cost of readability and maintainability. The best of both worlds would be to be able to work on nicely formatted and well commented CSS files while serving them as optimized as possible to our visitors.
The following handy little PHP script takes care of this! Simply place it in the same directory where your CSS files are and change your <link> tags like this:
<link rel="stylesheet" type="text/css" href="/path/to/cssdir/css.php?file=mycssfile.css" />
You'll be served nicely compressed CSS on the fly while you can happily keep working on mycssfile.css without having to worry about a thing. Let's compress our CSS!
You can see it in action by comparing my uncompressed CSS to the compressed version.
(continue reading...)
Filed under: programming
Number of comments:
Number of trackbacks:
Tagged with: 






