33

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.

3 Answers 3

39

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.

2
  • In addition I will say that some hosting providers make complains of forums and other widely used website that use gzip cause the higher CPU use that Jeff mentioned above. The answer is YES but check your hosting provider options first. Oct 28, 2010 at 10:12
  • Well, there is a risk of a BREACH attack. If you decide to use gzip compression MAKE SURE to use the Same-site cookie attribute, but even then there will be a small percentage of users with old browser versions at risk... Jun 13, 2019 at 21:32
18

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.

9

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.

3
  • how can i avoid compressing these files in apache ?
    – GorillaApe
    Oct 28, 2010 at 10:32
  • 4
    Use AddOutputFilterByType directives - see the mod_deflate entry in the Apache manual for further information: httpd.apache.org/docs/2.0/mod/mod_deflate.html
    – danlefree
    Oct 28, 2010 at 11:04
  • 1
    Most compressed media format also gain very little benefit from being zipped. That includes MP3, AVI, MP4, MPG, and PDFs. Oct 28, 2010 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.