Comparison of JavaScript compression methods
Friday, November 30th, 2007While creating the build system for our Java web application, I set out to do some benchmarking on some of the different JavaScript compression methods. When our project builds, I configured our Ant build script to create three different version of our JavaScript files; full source, minified (comments and whitespace removed), and packed (compressed).
I also configured Tomcat to use gzip compression and then ran six different test, the three version of our JavaScript files without gzip compression and the three versions with gzip compression.
I measured the load time and size using FireBug from within Firefox and recorded the following results:
| Full Source | Minified | Packed | |
|---|---|---|---|
| Without GZIP | 167 KB | 329ms | 95 KB | 281ms | 70 KB | 313ms |
| With GZIP | 67 KB | 297ms | 48 KB | 219ms | 47 KB | 312ms |
Although my “tests” are very informal, I think that it is clear that the minified version with GZIP server compression offers the best results. It is only slightly larger than the packed version in size, but it loads almost 30% faster (due to the overhead of decompressing the packed version).
