HTML whitespace "compression" - don't bother!
11 March 2013
This morning I came across this site on Hacker News. It's a cute site with some basic tips on how to make your sites faster.
It's very much a for-beginners document as all the tips are quite basic. For example it doesn't even mention the use of CDNs.
One tip in particular stood out to me: "it can be useful to minify your HTML with automated tools."
And it links to the htmlcompressor project. Ignore this advice.
What matters 10 times more is Gzip compression. This is usually very easy to set up with Nginx or Apache. It's not something you do in your web framework and if you don't have a web framework, you don't need to manully Gzip HTML files on the filesystem.
For example, downloading the home page here on my blog, at the time of writing, this is: 66,770 bytes big. Hefty, sure, but with all excess whitespace removed it reduces down to 59,356 bytes. But that really doesn't matter when you Gzip.
Gzipped from original version: 18,470 bytes
Gzipped from whitespace trimmed version: 18,086 bytes
The gain is 2% which is definitely not worth the hassle of adding a whitespace compressor.