At least it does for web pages.
“Try holding your breath for as long as it takes your home page to load. If you are now dead, it took too long.”
- Art and the Zen of web sites
A decade ago, in the age of dial-up connections, page weight was everything. Images were compressed to within an inch of their lives and Netscape (R.I.P.) even had a special attribute for a lower resolution image to use as a placeholder while the proper image loaded. Then along came broadband and web developers got lazy.
Now as mobile connections are more prevalent, size is once again an issue thanks to the EDGE technology of the current iPhone. Web 2.0 interaction and design tend to rely on extensive use of style sheets and client side scripting which can easily run to a couple of hundred kilobytes. Servers can automagically compress these text files (HTML documents, CSS and JavaScript) using mod_deflate or mod_gzip for Apache for example. As part of their tips to improve web page performance Yahoo offer a compressor to minify and squeeze file sizes down even more. Taking the hefty Prototype JavaScript framework as an example we can see the effects of these compression techniques:
- Prototype: 126KB
- gzipped version: 28KB
- Minified: 71KB
- Minified and gzipped: 21KB
Minifying before this compression gives us a saving of just under 7KB. This may not sound like a lot but multiply this up and it results in a bandwidth saving of a gigabyte per day if the file is served at a rate of a little under 2 requests per second, which is not unrealistic for a popular site. Also remember that this is just for one file. Automating this extra minification step is easy enough if you’re developing on OS X or a flavour of UNIX. You can also add some functionality to your webserver if you want to really show off but I’ve come up with a way to reduce the steps needed to a single click with Windows XP:
- Download the Yahoo compressor and unzip it. It’s Java, so you’ll need to make sure that you’ve got the runtime somewhere on your path. I placed mine in the
C:Program Filesdirectory but if you decide that you want to put it elsewhere you’ll need to edit the batch file (see next step). - Download my batch file and save it to a directory that is on your path.
C:Windowsfor example. You’ll need to edit this file to reflect the location of the Yahoo compressor or if you upgrade to a newer version at sometime in the future. - Download and run my registry keys to install right click handlers to your context menu.
- Right click on a
.cssor a.jsfile and choose “YUI Compress”. A minified version will appear right alongside the original file with the extension.min.cssor.min.jsdepending on the original file.
Once your code is minified it is quite hard to read. If you don’t have access to the original formatted source JavaScript code available, try this beautifier to make things look pretty again.