Should I use gzip for compressing my HTML?

I saw from an online tester that my HTML can be compressed about 90%! Is it good practice to use gzip or not? I see that lot sites don't use it.

For me it would improve traffic, as some pages contain a lot of data (120 KB of HTML without the images) which can be compressed to a few kilobytes.

Answers 3

  • Yes. 120KB for HTML alone(!) can be compressed greatly. Together with the CSS and JavaScript files. This will speed up the browsing experience for your users and save you bandwidth on your server.

    You could implement the compression using your server-side script and cache the compressed files, thus easing the pressure on the CPU on busy servers.

  • Yes, there is almost no reason I can think of to not use GZIP at all times. It's like getting free bandwidth, and it is universally supported. Always have it on!

    The only possible downsides are

    1. If you are on a shared host with very limited CPU resources, as the compression is done on the server and it does take a tiny bit of server CPU. The server would have to be very overloaded and/or extremely old for this to matter in practice, though.

    2. If you serve up very large (and by large I mean 400 kilobytes and up) dynamic web pages. Compressing very large dynamic content on the fly can be prohibitively expensive.

    But these are both rare edge conditions in my experience; 99% of the time HTTP compression is a clear win.

  • Is it good practice to use gzip or not?

    Depends upon your webserver's environment.

    If your server is running low on idle CPU time, adding GZIP deflation could actually slow down the rate at which your server responds to requests.

    If you're not presently dealing with a CPU bottleneck, however, GZIP deflation is a great idea but only for plain-text files.

    Most image file formats (i.e. PNG, JPG, GIF) are already compressed and GZIP deflation is a waste of CPU time.

Related Questions