GZip Compression and Wordpress

Tue, Jun 2, 2009

Featured, Tech, Wordpress  




cpu-load

Wordpress is known to be resource intensive and memory intensive blogging platform. Without optimizing, if you use Wordpressas-is” you are bound to face the wrath of your host, eventually resulting in the website downtime.

In case you have a heavy theme with lots of images, JavaScripts, CSS etc, you would be needed to worry about “Bandwidth” as well. Everytime you type www.techpp.com into your browser to read this blog, the browser sends a request to the server located at www.techpp.com to get the content. The server reads the request, processes it and sends back the requested data back to the browser.

For example, if you request a web page that is 25,024 bytes long, the web server sends the entire 25,024 bytes to the browser. In other words, the data is sent in its “raw” or “natural” form.

Data Encoding / Data Compression

Almost all the web-browsers these days are capable of sending a parameter Accept-Encoding as a part of the header request. This tells the web server that the browser can accept encoded/compressed data as well. If the server so chooses, it selects one of the encodings that the browser supports (the browser sends a list of supported encodings) and compresses the data with the selected encoding algorithm. Instead of sending a 25,024 byte document in the example above, it might end up sending a 10,567 byte long document which is a significantly lesser data transfer.

GZIP Encoding

“GZIP” or “gzip” refers to compression/decompression algorithm used by the gzip application (gzip application is used to compress and decompress data on UNIX/Linux machines).

A web browser that understands gzip encoding sends an Accept-Encoding header that looks like this:

Accept-Encoding: gzip

The web server encodes the data using the gzip algorithm and sends back the appropriate Content-Encoding header:

Content-Encoding: gzip

The browser then uses the gzip decoding algorithm to return the data to its normal, uncompressed form.

How GZIP encoding saves bandwidth and improves performance?

The idea behind gzip encoding is to reduce the amount of data being transferred over the network. In the example above, the size of the data was reduced by over half. Not only does the data transmit more quickly, bandwidth consumed will be less as well.

Gzip compression and Wordpress

I hardly have much knowledge on Wordpress core files. From whatever I know, in Wordpress 2.8 beta, hooks for gzip encoding have been provided for the plugin/theme designers. But I believe GZip encoding and compression should be enabled by default within Wordpress core (which I believe is not the case right now).

Plugins like wp-super-cache provide this feature to gzip the content, which in turn compresses the data (js and CSS) and ensure better performance and lower bandwidth usage. But why a plugin must be doing this? Why not it be a feature in Wordpress?

I request people who know about Wordpress to comment on this and correct me if I am wrong anywhere.


If you enjoyed this post, make sure you subscribe to my RSS feed!

Related Posts:

  1. 13 Most Important Things to do When Changing the Wordpress Theme
  2. Ultimate Resources to Help Secure Your Wordpress Blog
  3. Top 10 Wordpress Plugins for Login
  4. A Digg Like Resource Exclusively for Wordpress – WpVote
  5. Top 10 WordPress Gallery Plugins





, , , , , , , , , ,

10 Comments For This Post

  1. Nihar Says:

    Raju,

    Nice post. I am on the same boat as you are.

    But, i have a question. If we enable gzip compression. Does every request not make extra burden on hosting service. which needs to first gzip it and then send the data to the client?

    Nihars last blog post..How to Block Visitors / Traffic from a Specific Country

    [Reply]

  2. Christopher Ross Says:

    I’m curious, while GZip would decrease bandwidth concerns wouldn’t it increase CPU usage?

    Christopher Rosss last blog post..Google articles in the news

    [Reply]

  3. Pavan Kumar Says:

    I don’t have any knowledge about all these technical stuffs, but what I experienced with my previous theme (the complete version of the existing one) was that the gzip compression screwed the appearance of my blog badly, then I remove it. First I need to test WP latest version on localhost before I use it on live website.

    Pavan Kumars last blog post..What Search Engines Think of “Search Engine”?

    [Reply]

  4. Raju Says:

    @Nihar,
    Its not every request, only the first request will have the content g-zipped, for the following requests, it will serve the already compressed data directly (thereby saving CPU resources)

    @Ross,
    It doesn’t increase CPU usage (assuming you don’t clear the cache too frequently)

    @Pavan,
    I do not know what was wrong with your theme, Possibly CSS compression was not done properly, but it works perfectly fine in my themes

    [Reply]

  5. Public Records Says:

    I had not tried it but heard about many time from my friends. After reading you article I thinks that why don’t have try it. its seems very useful.

    [Reply]

  6. Gautam Says:

    Well, I use YSlow Plugin by Yahoo with Firebug. I tested it on your site and it gave your site 53 marks (Grade E), though your site loads in 7.674 seconds.
    It also tells to compress components with gzip.. but I have no idea about it :-( .

    Gautams last blog post..Create Your Personalized Yahoo! Messenger and Chat With Your Friends on Orkut

    [Reply]

  7. Business Computers Says:

    After reading through your article I’m tempted to try out your suggestion. But the issue is that I’m not certain what the outcome will be with the present theme that I am using. Some friends claim the theme may go haywire if it is not standardized.

    [Reply]

  8. Mohan Says:

    I strongly support your suggestion for enabling the transfer of compressed data. Most of the current browsers do support gzip and I don’t find any reason why it shouldn’t be a part of wordpress core library code.

    [Reply]

  9. Harsh Agrawal Says:

    I’m doing my research on Optimizing Wordpres and many people has written about gZip. though many people prefer other techniques and before implementing gZip into my blog, I wanna see..what other users review are saying…

    [Reply]

  10. Trackbacks Says:

    [Reply]

Leave a Reply