HTML whitespace "compression" - don't bother!

11 March 2013   4 comments   Web development

Powered by Fusion×

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.


Ah you really made a post about it! :D

Well a purist could argue that if you know about the waste: prevent it!
For the browser itself there is no need for the whitespace and xml can be indented automatically to your very taste locally when you want to edit it.

Even gzipped this saves about 4mb traffic on 10000 pageloads...
I read people arguing against SEO-style-readable-urls being a tremendous waste counted on a large scale ;]

So why stop there? You're already doing stuff WAY beyond most of the web devs! And I think thats awesome!! :]
for big sites 2% is a lot tho. i'm surprise the diff is so big.
How do you estimate all this stuffs? (I mean with ur old posts fancy-cache, ...) Can u post steps or tutorial? Thank you
How does this sound?

Pages are quantized into packets. If that 2% happens to tip you over a TCP packet boundary, you've saved 1 RTT.
Thank you for posting a comment

Your email will never ever be published

Related posts

django-fancy-cache with or without stats 11 March 2013
premailer now honours specificity 21 March 2013
Related by keywords:
Comparing Google Closure with UglifyJS 10 July 2011
The awesomest way possible to serve your static stuff in Django with Nginx 24 March 2010
Gzip rules the world of optimization, often 09 August 2014
A Django base class for all your Forms 16 November 2013
Automatically strip whitespace in Django forms 12 October 2009
Optimize with 15 February 2005
ztar - my wrapper on tar -z 29 June 2005
How to use premailer as a command line script 13 July 2012
Gzip and Slimmer optimization anecdote 30 January 2007
Comparing YUI Compressor and slimmer 17 November 2009
Comparing jsmin and slimmer 17 September 2009
slim, a new free web service for white space optimisation 25 July 2006