While 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).
Hi, how can i “GZIP” .js files using windows?
Is there any GUI mode?
Or like the Packer URL version? (https://dean.edwards.name/packer/)
Cheers!
Santiago.
@Santiago – gzip, as mentioned here, refers to the HTTP response compression by a web server and decompression by the web browser. So it’s not something you can physically do to a file. (UPDATE: Yes, you can physically compress a file using gzip, but this post is referring to server compression – thanks Peter)
Here is a great article that explains it all:
https://www.webreference.com/internet/software/servers/http/compression/
OK. thanks!
Eric: gzip is the standard compression used on unix machines, it is indeed something a user can do to a file. WinZip and other Windows archiving platforms support compression and decompression.
Also see another take on the question.
@Peter – I prefaced my response with “gzip, as mentioned here, refers to…”. I’ll change last sentence to be more clear, but again, I was speaking in terms of server compression not physical file compression.
How can I use javascript compression with IIS?
@dnd – IIS 5.0, IIS 6.0, or IIS 7. HTTP Compression is not available in IIS 5.1 [reference]. I also don’t think IIS 4 or lower support HTTP compression natively…you’d need to install third-party software.
IIS version -> OS version list:
https://en.wikipedia.org/wiki/Internet_Information_Services