Welcome to WebmasterWorld Guest from 18.205.176.85

Forum Moderators: phranque

Message Too Old, No Replies

Gzip compression levels

     
2:27 am on Jun 18, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Mar 15, 2013
posts: 1205
votes: 120


I can't really update to HTTP/2 yet, so I'm still playing with Gzip compression.

I'm using WHM/cPanel, and the default compression level is set to 6 (out of a possible 0-9). But the explanation is kind of vague:

The level of compression to use (0 is faster but less compression, 9 is slower but provides maximum compression)

Can you guys suggest what gains or losses there might be to change this to a higher or lower number than 6? Would a level of 9 mean that the CPU works the hardest, but bandwidth usage is the lowest?

Further, is there any reason to compress images, or should I just stick with text/html, text/plain and text/xml (I'm guessing that text/plain would cover js and css)? My sites mostly use compressed PNGs, but there are some JPGs and GIFs.
2:37 am on June 18, 2018 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15941
votes: 889


My sites mostly use compressed PNGs, but there are some JPGs and GIFs.
I think it was keyplyr who explained in another thread that compressing jpgs will lead to unintended consequences, since the format itself is already compressed.
2:46 am on June 18, 2018 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member tangor is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 29, 2005
posts:10590
votes: 1127


Adding compression to already compressed objects is a waste of processing. Stick to compressing objects which are not compressed.

As to whether increasing the gzip level above where it is now can only be determined by real world testing on your site. Try it and see if there's a benefit (whichever direction you wish to go). My experience is 6 is the sweet spot.
6:38 am on June 18, 2018 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:12913
votes: 893


Yes, deflating a compressed file will actually add processing time as well as increase the file size because it strips out the meta data that compresses them more lossless in the first place, so leave out .jpeg & .jpg from your Gzip list.

[fix typo]

[edited by: keyplyr at 6:46 am (utc) on Jun 18, 2018]

6:45 am on June 18, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Mar 15, 2013
posts: 1205
votes: 120


I think you guys will find this interesting, too:

[catchchallenger.first-world.info...]

The test run was of a file that's 445MB. A compression level of 5 took it to 98MB, 7 was 96MG, and 9 was 96MB. So it appears that the difference from 5 to 7 is marginal, and from 7 to 9 is virtually nonexistent.

I've had my sites set to compress everything, but I see now that I was just using up memory for no reason :-(
6:58 am on June 18, 2018 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:12913
votes: 893


Different file types deflate more than others. For example, HTML will deflate up to 70% compared to the normal file, depending on overhead, likewise with JS and other flat files. Image files yield the least savings but will show good in tests.

Note that tests are much different than real world browser experience, with all the influences (server response & redundancy, network traffic, connectivity, browser speed, caching, etc.)

While compression is a must, especially on mobile, reducing server calls is probably the most prudent way to increase page speed.
9:10 am on June 18, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Sept 25, 2005
posts:2091
votes: 370


text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/vnd.ms-fontobject application/x-font-ttf

These are the MIME types I tend to default to for gzip and Brotli compression (though I may not actually use them all).

JPEG optimization is certainly possible these days, with virtually no visible loss of quality. There's guetzli and mozjpeg, for example. Or try running a few of your JPEGs through some good online compressors to see what's possible. Regarding PNG, there are multiple approaches to optimizing those, and I tend to run through at least a couple of them. Then I convert to WEBP, which is likely to result in additional bytes saved. I say likely because in some cases the WEBP may actually end up larger than the PNG, so you'll need to test for that.

As for gzip compression levels, 5 is my default, and 9 is the obvious choice when pre-compressing files.
6:15 pm on June 18, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Mar 15, 2013
posts: 1205
votes: 120


@robzilla, I notice that you don't have text/html listed... is that automatically included in text/plain? I thought that CSS and Javascript would be include in text/plain, but I see that you have them listed separately
9:42 am on June 19, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Sept 25, 2005
posts:2091
votes: 370


Oh, sorry about that. I use nginx and it always compresses text/html [nginx.org].

If your web server doesn't do that, then yes you should probably add it to the list.

text/plain only applies to things like .txt files, and probably as a fall-back. If you serve your CSS as text/plain, however, I believe it may not be recognized as a stylesheet by the browser. So your web server should serve it as text/css, Javascript as application/javascript, etc.