Compress your CSS

Saturday Mar 24 2007

This article has been rendered obsolete by this newer article. Read it for updated and better code.

As all web developers know, 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 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 on the fly while you can happily keep working on mycssfile.css without having to worry about a thing. Let's our CSS!

You can see it in action by comparing my uncompressed CSS to the compressed version.

(continue reading...)
bookmarking

Popular Articles

    Technology Blogs - Blog Top Sites

     

    • Featured Links
    RockySomewhere near the Orion NebulaBookalicio.usGolden Gate BridgeThames River BankJackie and mePimpin' it