Thursday, 6 December 2007

24ways: Minification: A Christmas Diet

Another excellent entry to 24ways for 6th of December. Gareth Rushgrove writes about the necessity to minify HTML, CSS and Javascript for todays web applications.
With all the added Web 2.0 features these days, minification of HTML, CSS and JS cannot be stressed more! Web applications of today are growing into bigger proportions no only content wise, but also form the point of sourcecode.

Minifying your Javascript files or using preminified versions of your favorite Javascript framework is a must, since like your CSS files, these will be generating alot of bandwidth.

At my workplace we decided to adapt existing minifying methods for CSS and Javascript and tie the minification into the Webserver process, using PHP and Apache mod rewrite rules to both minify and cash CSS and Javascript files. This way we are able to reduce the load on sites generated from these files by manyfold, making YSlow cheer at the small file sizes and less loadtimes.

The Apache mod rewrite rules will pick out CSS and Javascript requests to the server and parse them through our PHP Minifier, which will check for an update to the cashed file and minify the code at the same time. To reduce requests even further we added the possibility to load multiple CSS and Javascript files with less requests, by tying them together, when the browser reads the HTML Source.