Should I use gzip for compressing my HTML?
Solution 1
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.
Solution 2
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
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.
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.
Solution 3
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 videos on Youtube
GorillaApe
Updated on September 17, 2022Comments
-
GorillaApe over 1 year
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.
-
Ankit Sachan over 13 yearsIn 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.
-
GorillaApe over 13 yearshow can i avoid compressing these files in apache ?
-
Jonx over 13 yearsUse
AddOutputFilterByType
directives - see themod_deflate
entry in the Apache manual for further information: httpd.apache.org/docs/2.0/mod/mod_deflate.html -
Lèse majesté over 13 yearsMost compressed media format also gain very little benefit from being zipped. That includes MP3, AVI, MP4, MPG, and PDFs.
-
goulashsoup almost 5 yearsWell, 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...