Gzip Compression Rocks

By Daniel Scocco

Today I received an email from Luciano Passuello, a long time DBT reader. He basically told me that he was running some bechmarks on website load performance, and that Daily Blog Tips was performing very good according to his tests. The only point where it could improve was on the Gzip compression.

I wanted to test with Gzip compression for a long time, so today I got off my butt and did it. In fact the WP Super Cache plugin for WordPress lets you activate Gzip compression with one click (it is called “Super Compression”).

Boy, it did speed things up, so much that I could see it visually. How so? Before activating the Gzip compression, when I loaded the homepage of the blog, I could see the sidebars loading. After the compression was activated, I was not longer able to see the sidebars loading. You can test it yourself moving between the homepage of the site and the individual category pages. You should just see the main content changing, almost as if the sidebars were not being loaded at all. (This test does not work with single post pages because I have an Awever Javascript form there, which is not hosted on the blog)

Luciano also found the code that you need to add to your .htaccess file if you are not using the WP Super Cache plugin (source here):

# Turn GZip compression on (as per http://tr.im/fnn6)
<Location />
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>

Keep in mind that not all servers support Gzip compression. If in doubt, email the support service of your hosting company.

If your server supports it, though, I highly recommend that you give it a try. It just rocks.



Related Articles

Please install the YARPP plugin

Share

26 Responses to “Gzip Compression Rocks”

  • Preetinder

    Your site doesn’t seem to have Gzip compression right now.
    Why did you disable it?

  • Keith Davis

    Hi Daniel
    Tested this page using the GZip compression tool.
    Said that this page was not GZipped – have you stopped using it?

  • Tim Koschützki

    I too noticed a decrease of visitors by 80%, from all traffic sources, so it must be gzip. I am now turning it off again to see if traffic recovers in GA.

  • Medyum

    Compression is always a good idea. I only want to add that there is no single solution here, what works and how to enable it is highly dependent on specific hosting settings.

    At my blog deflate filters do absolutely nothing and same with WP-SuperCache setting (which I didn’t like much overall, using HyperCache now).

    Took me insane amount of time to make it work using PHP zlib compression.

    By the way YSlow (Firefox plugin) is awesome tool that shows compression on all elements (not only HTML) and many other performance things.

    @Todor Christov

    Quite possible that you broke page display for one of browsers (probably IE). Many compression code snippets fail to mention or address compatibility issues they have.

  • ayman

    good work

  • Gregory Raby

    Compression is great, compression is fantastic… but :

    – Test it on a sister site before putting the changes live to production. Lots of hosts won’t support it the standard way (i.e. 1&1 doesn’t support gzip)
    – Compression HAS to take place at the server level or you will lose a good share of the benefits

    Ultimately, compression is not always the best thing ever to boost your site performance: reducing the http requests can be times and times more impacting, using a content delivery network (i.e. amazon S3 if you go cheap) is a must for global media sites.

    As I’m using 1&1 as a host (I need cheap & efficient, I know it has drawbacks), I can’t properly use gzip. Given they host a few other sites, I suggest people to use the “Yslow” plugin from Yahoo! for very valuable insights.

    Godd luck
    Greg

  • Johan

    The reason you can not see the side bars loading any more it is compressed and the browser can only start displaying the contents once all the data is there.

    This excludes stuff like images that the browser executes separate http gets for.

    Johan

  • Fatin Pauzi

    Yea, I admit. DBT load faster than before. I’ll try the plugin. Thanks!

  • bebek oyunları

    Can’t wait to try…
    Thx…

  • Kurt Avish

    Daniel, I guess you meant “because I have an Aweber Javascript in the third paragraph above?

    Concerning the gzip, I guess I am gonna try it. My blog is hosted on Doreo too now, if it works for you I guess it will be on mine too 🙂

    I always looked at the option in Super Cache panel but was alway reluctant to activate it. Gonna try it today.

    Out of subject: How many of you use the Turbo mode of wp here for the dashboard? Since I have activated that, the dashboard really flies.

  • Daniel Scocco

    @Hendry, thanks for adding that.

  • Hendry Lee

    Here’s a few things you may want to add, Daniel.

    First of all, it is always a good idea to perform the compression at the server level, NOT in a plugin in the code space. That’s why compression has been deleted from core WP.

    Holding execution longer in PHP cause memory and server hog, which is very valuable in high load server.

    But compression using WP-Super-Cache is the exception because it stores the compressed file for later use until it expires.

    Next, if CPU resource is available, you may want to set compression level to a higher degree (1 – lowest to 9 – highest compression). 9 produces the smallest file but rarely used for compressing files on the fly. That’s too slow and cpu intensive.

    Lastly, WP-Super-Cache with compression will generate two versions of the cached page. One without compression and one stored in compressed format (.gz).

    It wastes more space but spaces are cheap nowadays. It is necessary to add the code to enable Apache (or any web server) to return the compressed file first before the uncompressed file. Otherwise, enabling the compression will only compress but Apache won’t use it.

    My web server software, nginx, automatically looks up for .gz file in the same directory and return that, so this happens automatically without setting up the additional rewrite line specifically to detect .gz files.

  • Tom Bradshaw

    If I can I’ll have to use this for my own blog, thanks alot!

  • Another Way To Earn Money

    This is really nice inpo……….

  • Harrison

    Just wanted to let you know I have your feed on my My Yahoo and enjoy reading your articles.

  • Rarst

    Compression is always a good idea. I only want to add that there is no single solution here, what works and how to enable it is highly dependent on specific hosting settings.

    At my blog deflate filters do absolutely nothing and same with WP-SuperCache setting (which I didn’t like much overall, using HyperCache now).

    Took me insane amount of time to make it work using PHP zlib compression.

    By the way YSlow (Firefox plugin) is awesome tool that shows compression on all elements (not only HTML) and many other performance things.

    @Todor Christov

    Quite possible that you broke page display for one of browsers (probably IE). Many compression code snippets fail to mention or address compatibility issues they have.

  • Himanshu

    Looks useful. Will definitely give it a try soon. Bookmarked!

  • Frank

    @Luciano,

    I was actually going to suggest that tool 🙂 A lot of web hosts have content compression (gzip compression) turn on for shared/reseller servers by default. It usually causes no problems for clients and saves on bandwidth.

    Your mileage will vary if you try compressing things like css javascript etc. Some browswers like it others don’t.

  • Luciano Passuello

    Hi Daniel, glad it worked out well for you!

    A good way to verify the gains due to GZip compression is by using this tool.

    Running it on this exact page:

    Original Size: 21.78 KB
    Gzipped Size: 7.26 KB
    Data Savings: 66.67%

    Also, bear in mind that Super Cache’s GZip support will only compress the html pages. If you use the .htaccess version, you’ll compress other served files, too (such as CSS files), resulting in gains even greater.

  • Daniel Scocco

    @Todor, thanks for letting us know about that.

  • Todor Christov

    Daniel, this is a good tool for compression, just bear in mind that there is a possibility to receive a decrease in your stats.

    I have tried it two weeks ago and it suddenly turned out that my statistics shows around 25-30% less visitors (I use both GA and Clicky). After deactivating this option everything recovered again.

    This is why I concluded that it might be connected to GZip.

  • Daniel Scocco

    @Vygantas, I don’t use AdSense or cpc ads on this blog, so this won’t affect me.

    Even if I did I am not sure if I would put CTR over loading performance though 🙂 .

  • Vygantas

    if it will load*

  • Vygantas

    It’s a great technique, not sure if it’s for blogs though 🙂

    If you have read a recent post on some seo blog (dont really remenber), it said that ads ctr increased when page loaded slowly due to server load. So it’s wise to think that if will load ultra fast = less ctr.

    Haven’t tested myself though, but if your earnings drops after gz, keep that in mind.

  • adis

    Can’t wait to try…
    Thx…

  • Boerne Search

    I’ll contact my server. Thanks for the heads up. But if something goes wrong, I’m coming back here. 😉

    Kane

Comments are closed.