We all know attention spans on the Web are small. Make a potential first time visitor to your site wait more than a few moments for your blog to load and they’ll click away faster than you can say, “But wait!”
Here’s an incredibly easy trick you can do to reducing that “but wait”-time for your blog to load. In most cases, it’s as easy as copy & paste.
Now who doesn’t like the copy, paste, and done tutorials?
Let’s first show you what to do and then for those who are interested, we’ll talk about what we did (in easy terms).
Copy This and Put It Here
Copy
<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], ‘gzip‘)) ob_start(“ob_gzhandler”); else ob_start(); ?>
Paste A (for WordPress users)
For WordPress users, paste the code up at the very top of your header.php file (above the DOCTYPE line). If you’re not sure how to do this, see the video at the end of this tutorial.

Paste B (for static .html pages)
If your website is coded in html and not php, then what you’ll need to do is copy the code above and paste it up at the very top of each web page you want to compress (above the DOCTYPE).
The one change you’ll need to do here is change the extension of your web pages from .html to .php.
So for example, change: index.html to index.php
What Did We Do?
Without going into a bunch of techno talk, we basically instructed, through PHP, that the Web server compress files for transit to your visitors’ Web browser by use of gzip.
I’m sure you’ve seen zip files before (myfile.zip). Zip is a compression utility that takes a bunch of data and files and compresses them into one smaller size file.
By using gzip, we compressed your blog’s data into a smaller file size before sending it over to your visitor’s Web browser. As a result, your blog loads faster for your visitor.
Simple. Easy. Works.
How To Test It
Of course you’ll want proof that your site is loading quicker. You should notice a difference in load time just by clicking around your blog before and after the line is pasted in. But if you want to see actual data, head over to http://www.port80software.com and type your blog’s address in the Compression Check box.
Here’s the results for my blog. I circled the parts that showed my after compression data.

As you can see, my blog loads more than 4 times faster with the gzip compression enabled.
Also, the file size transmitted over the Internet and to my visitor’s browser was reduced from 60,241 bytes to just 12,963 bytes. That’s a 47,278 difference in file size!
WordPress How-To Video
For those who like videos, here’s how to copy and paste this command into your WordPress header.php file.
Share It
This little tip has helped many people decrease how long it takes their sites to load. If you have a moment, please consider sharing it through your social networks like Stumble Upon, Twitter, etc. While you’re at it, feel free to follow me on Twitter.
















June 26th, 2010 at 3:06 pm
Hey John.. I’ve found a plugin called W3 Total Cache that has helped me MASSIVELY increase loading times by using compression, page caching, and database caching. I had never heard of it before I tried it.. always heard of WP Super Cache, but i find W3TC to work much better, it has memcached and CDN support, and just an overall great plugin. It might be worth mentioning in a future update to this blog post and compare the caching/compression plugins that exist out there.
Aaron´s last blog ..Free Blogs
June 26th, 2010 at 3:13 pm
Hi Aaron, yeah I’ve heard of that plugin as well and I tested once a while back but I think it conflicted with another plugin or something else that I was doing, so I stuck with the WP Super Cache.
The W3TC plugin looks to work really well. Thanks for the input.