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.

















September 8th, 2009 at 10:32 am
I did it! Yay!!!! 3.5 times faster now for me. That will no-doubt be an amazing boost in the Stumble It world.
Thank you, John. Are you this nice in “real life” too?

Jannie Funster´s last blog ..What To Do When The Power Goes Out
September 8th, 2009 at 10:39 am
For future readers of this post, DO THIS paste into your HTML.
It is just AMAZING how much faster my blog loads, like lightening now. Thanks again, John!
Jannie Funster´s last blog ..What To Do When The Power Goes Out
September 8th, 2009 at 10:13 pm
Re: Thank you, John. Are you this nice in “real life” too?
Yes, unfortunately. hehe Sometimes being too nice means being taken advantage of or thinking people think the way I do (as a person not out to steal from you); this has not always worked well for me LOL.
I’m happy it worked well for you. It’s a simple little compression you can do to speed things along.
Got your email by the way, you are a way cool chick. Thanks!
September 9th, 2009 at 7:44 am
Oh yah! me ‘way cool, hee-hee!

Jannie Funster´s last blog ..What To Do When The Power Goes Out
September 9th, 2009 at 10:22 pm
Thank you John for the info. I was directed here after Jannie’s advise about the code. Appreciate you sharing the tips to speed up loading time.
Keep up the good work!
@wchingya
Social/Blogging Tracker
Ching Ya´s last blog ..16 Social Bookmarking Plugins to Promote Your Posts
September 10th, 2009 at 3:59 am
Hi Ching Ya, nice to see you here. Glad you stopped by and no problem about the code. It works pretty good, doesn’t it.
Maybe I’ll come up with another WP speed post here shortly.
September 10th, 2009 at 7:43 am
That sounds great! Will be anticipating for it, surely!
Thanks John. Like Jannie said, you’re a nice guy.
Keep it up!
Ching Ya´s last blog ..16 Social Bookmarking Plugins to Promote Your Posts
September 10th, 2009 at 11:27 pm
Hey this is cool. Speeding up the blog loading will surely like by the readers.
Thanks for sharing it with us John.
Michael
MichaelR´s last blog ..How to Improve VoIP Call Quality
September 11th, 2009 at 2:38 pm
Hi HichaelR, no problem. Thanks for stopping by!
September 23rd, 2009 at 3:10 am
I have enabled this on one of my blogs and it show great acceleration.. But my other shared hosting package doesn’t support it. What a pity, I’ll have them upgrade the apache
Regards
Combson
Combson Yachts´s last blog ..Isa 600 Superyacht Review with complete photos gallery
September 23rd, 2009 at 4:27 am
Hello Combson, thanks for stopping by and leaving a comment.
Let me first tell you, I love your blog. What I’d give to have a yacht like, well, anyone of those.
Feel free to open a hosting account with us if you need new hosting. All our tutorials are through using our control panel.
Compressing your data before transit really does help speed things up. My buddy said he had to “change his shorts” after he saw how much improvement his blog had. That was pretty funny.
I’ll try and do a follow-up article with some more tweaks you can do to speed up load time.
Thanks again for stopping by.
October 12th, 2009 at 8:43 am
Thanks for the tutorial.. If this works, I’ll be sure to pass this on to my readers!
October 12th, 2009 at 8:48 am
Doesn’t seem to be working for me… My shared host must not support it either. LAME – This looked really promising.
October 12th, 2009 at 12:44 pm
Hi Brad, hey nice blog you got there. I liked the reCaptcha “Ugg Why?” image LOL. I’m not a subscriber. Do you have a Twitter account I can follow? It seems we both like toying with WordPress.
Hmm, this compression should work with most web hosts. It could be a plugin which is causing the problem. Try experimenting with pasting in the code and deactivating some plugins.
I ran into issues with this code while using the Head Cleaner and WP Minify plugins.
October 13th, 2009 at 4:38 pm
Yea it turns out that my web host doesn’t support it… I got an email back saying that they didn’t have it installed.
You think a webhosting company wouldn’t want to save bandwidth costs in any way possible! I found another tutorial for zlib compression which is working quite well on my blog. I plan to write a post about this trick as well as the other I found. Of course you’ll get a juicy backlink!
Your blog is very professional as well. You did a great job customizing it – I look forward to reading more from you

Brad Ney´s last blog ..BradBlogging’s 2nd Anniversary Makeover With A New Design and Mindset
October 13th, 2009 at 7:40 pm
Brad, glad to see you over here and thanks for the kind words and link back. Actually, I felt my last blog design was too corporate (it was an extension of our “company’s” website [which also got a redesign]).
Since I’m really the only blog author for our company, I wanted to make this blog more of an extension of me and what I do, rather than what our company has a blog about. Glad you like it, thanks.
As I recall, zlib is simply another form of gzip. Did you need to upload a php file to the server and then call it through .htaccess?
When you’re finished with that article, would you please come back here and leave a comment with a link to it? After all, that’s what we’re all about, right? Helping everyone learn.
October 15th, 2009 at 9:24 am
Hey John.
Tried signing on to your site yesterday, but there was a 500 error
You can view the post at: http://bradblogging.com/tutorials/speed-wordpress-up-3-times-as-fast-under-a-minute/ which shows you how to use zlib compression on your Wordpress blog.
I think you’re right about zlib being another form of Gzip.
I simply added the code to my header and was good to go!

Brad Ney´s last blog ..Is Your Wordpress Slow Loading? Make It 3 Times As Fast In Under A Minute
October 15th, 2009 at 10:08 am
Thanks Brad, I’m headed over there now.
The 500 error was due to some upgrades to our servers which my blog and our site is hosted on. Sorry about that but it’s all squared away now. By default, the server now has directory browsing disabled, which is a nice little security feature our customers no longer need to worry about implementing themselves.
October 15th, 2009 at 1:31 pm
Thats cool. Directory Browsing “support” sucks on Wordpress.. I had to upload blank index.html files to each directory!

Brad Ney´s last blog ..Is Your Wordpress Slow Loading? Make It 3 Times As Fast In Under A Minute
October 15th, 2009 at 2:29 pm
To make things a little easier on you, you can disable directory browsing through your .htaccess file (so you don’t have to create all those index files).
Put this in your root .htaccess file and no one will be able to browse directories like /themes and /plugins which may not have index files:
Options -Indexes
If you stick with the .html files, you could add a Javascript redirect to automatically redirect people away from your /plugins directory to your home page.
November 1st, 2009 at 10:51 pm
I gotta give this tip a try and see if it improves my loading speeds even further. And John Hoff’s tip about the .htaccess above is spot on too…
Speaking of .htaccess, you can do gzip compression through htaccess too (the target files). If requires mod_deflate to be supported by the host (Apache 2.0 I think). mod_gzip is available for hosts not supporting mod_deflate. The code is relatively long, so I won’t paste it here, but you should find it if you search the web for “htaccess rules mod_deflate” or such.
Antti Kokkonen´s last blog ..Analyzing the State of the Blogosphere 2009
November 2nd, 2009 at 6:48 am
Hi Antti, thanks for stopping by. I have an article on using .htaccess to compress your files here. .htaccess is suppose to compress a little better on paper, but in practice I really see no difference between compressing with .htaccess and PHP.
In fact, I like PHP because more people can use it and it’s also much easier to test to see if it’s working.
BTW, I tried commenting on your blog and the posting of comments seems to be not working. Ironically, I was commenting on the .htaccess tricks post you have and was mentioning how #4 broke my comment section a while back when I tried it. If you’re using that code, you might try disabling it and seeing if your comment section fixes itself.
November 19th, 2009 at 1:17 pm
Great Tip!
Do you know if using this method with interfere with using the Super Cache Plugin, or if either with negate the effects of the other?
November 19th, 2009 at 4:21 pm
Hi Richard. I use the WP Super Cache plugin and as you can see from the screen shots above it doesn’t interfere with compression.
The two work well together.
December 5th, 2009 at 8:34 am
Greetings, thanks for providing the info in this post. I’m looking into implementing gzip compression on my site, because Google’s Webmaster Tools Site Performance tool recommends applying gzip compression to the Google Analytics ga.js code on my site. I assume your PHP solution will successfully compress the ga.js code, as well as all other compressible page components?
Another question I have: By implementing your PHP gzip solution, do I need to be concerned about it perhaps not working properly with older browsers, such as IE 6?
I’m far from being an expert in PHP and in modifying .htaccess files, so I appreciate your sharing your knowledge on gzip compression. Thanks very much.
December 5th, 2009 at 10:03 am
Hi Deb.
Yes it does provide the compression, however, there are concerns with earlier web browsers. IE5 probably won’t be able to display your site. IE6 with sp1 won’t either, but users of IE6 with sp2 (service pack 2) should be able to.
So if you want to accommodate for those earlier browsers, you probably won’t want to use gzip.
December 5th, 2009 at 10:45 am
Thank you for your response, John. That’s helpful.
It’s excruciating for me to think I might be preventing even one visitor from accessing my site! In reviewing my stats, I see that IE 5 visitors account for less than 1% of my visitors for this year-to-date, and IE 6 visitors account for 24% of visitors. (I wish I could tell how many IE6 visitors were SP2.)
I realize I may need to hold a bigger perspective regarding my site’s efficiency. I’d be curious to know the perspective of other web masters when deciding whether to implement changes that may preclude or hamper older browsers, such as IE5 and some IE 6 visitors.
December 16th, 2009 at 9:12 pm
Hey John, I wanted to let you know that there’s a new Trac ticket for Gzip compression.
http://core.trac.wordpress.org/ticket/11453
The option for Gzip should be included in Wordpress as it already is for other major CMSes and blogging platforms. Thus, I hope in the next versions we can get support to include an option to turn it on preferably using the mod_deflate module but of course supporting other methods like ob_gzhandler if the developer chooses this is the best method.
Please spread the word so we can make this a reality by verion 3.0!
December 18th, 2009 at 4:56 am
That would be an awesome feature, Micah, especially since Google’s going to be paying more attention to the load times of our sites.
I would definitely suggest they provide support for the various types of compression out there. Some web hosts allow for one type while others don’t allow for others. It would be good to be able to accommodate as many people as possible.
December 20th, 2009 at 10:37 am
Hi John
I read this post when it first came out and whilst it was interesting, I didn’t think too much about it.
Tonight I’ve just checked my sites using Google Webmaster Tools and noticed that it now has a section for “page load times” – perhaps I’d just missed it in the past.
So I checked my sites… all my html sites are super quick but my single Wordpress site is super slow.
So I’m back to this post.
I’m sure that I read somewhere that “page load time” is now one of the metrics that Google uses to allocate Google Pagerank, so I have to speed up the site.
Hard to believe that such a small piece of code can make all that difference but if your site was four times faster, I’m prepared to give it a go.
I’ll let you know what my figures are.
Keith Davis´s last blog ..The eyes have it!
December 20th, 2009 at 11:10 am
Hi Keith. Keep in mind that this compression method could make users of IE6 and below have a hard time seeing your site.
I checked my analytics and I have a very small percentage of people who come to my blog using IE6, so I’m using the compression.
Another thing you can do to speed up your blog is use the WP Super Cache plugin. It’s a monstrous plugin and some people don’t like it, but most do. It’ll speed things up quite a bit. I use it.
John Hoff´s last blog ..How To Backup Your WordPress Blog’s Database With A Plugin
December 20th, 2009 at 11:23 am
Thanks John
I didn’t realise that it caused problems in IE6.
Thought it was too good to be true… might have to rethink that one.
What does “monstrous” mean in relation to the WP Super Cache plugin?
Keith Davis´s last blog ..The eyes have it!
December 20th, 2009 at 11:33 am
It adds code to your .htaccess file (and I’m not sure where else) and basically serves up your posts and pages as .html files. I’m not sure what all changes it makes, but I know that whatever it does, deleting the plugin is not standard. You have to do a few steps to completely delete it.
I wouldn’t worry about it too much, you can try it with no problems, most everyone does.
December 30th, 2009 at 1:19 am
I tried this trick twice and it isn’t working. My blog is hosted at Hostgator and it uses php not sure why it isn’t working. I wanted to try this before installing wp-cach or super cach because I have had those plugins in other blogs and they can botch things up. I’m no pro at coding but I did install this and update twice, nothing.
bah.
Deb´s last blog ..My Toshiba Satellite Explodes
December 30th, 2009 at 9:29 am
Hi Deb. It could be an issue with your web host. Brad (another commentator above) had a similar issue because the compression wasn’t compatible with his web host. The work around is to use zlib compression.
He wrote an article on how he got his to work here.
January 1st, 2010 at 6:24 am
Hi John
I’ve read the Brad Ney article and will give his zlib method a try.
Brad thinks that the zlib compression should be OK with IE6.
I’ll make sure that IE6 is behaving, check the speed using the “port80″ software and report back the results.
Keith Davis´s last blog ..Ooh la la…
January 1st, 2010 at 12:05 pm
Yeah let me know about IE6.
gzip is compatible with IE6 service pack 2, but anything earlier it is not. I thought zlib would cause the same issues though, but let me know.
John Hoff ´s last blog ..Aside From A Blogger, What Are You Really?
January 13th, 2010 at 9:25 pm
John,
There is a feature known as ‘Super cache compression’ in wp-super-cache which I have enabled as the code you have mentioned didn’t quite work out because of the theme which is quite complicated.
Can you let me know if this is the right thing to do? It shows as compressed

Rockstar Sid´s last blog ..Another Free Maxim Magazine Subscription For 2010
January 13th, 2010 at 9:47 pm
Hey Sid. Just checked your site and you’re compressed and ready to go.
The WP Super Cache compression uses gzip through .htaccess and is definitely another way of doing it.
So you’re all good.
January 23rd, 2010 at 11:45 am
Hi John
Still looking at speeding up via gzip.
Looking at my Google Webmaster diagnostics, I notice that google recommends using gzip so I’m going to give it a go.
Quick question…
The method you demo in the video uses code in the header.php, “WP Super Cache compression uses gzip through .htaccess” and I have spotted a few posts out there on adding code to .htaccess in order to activate gzip.
Is one method superior to the other, or is it simply a case of you pays your money….?
Keith Davis´s last blog ..Ooh la la…
January 23rd, 2010 at 3:50 pm
Hey Keith. There’s not much of a speed difference that I’ve seen between compression using PHP vs. .htaccess.
In general, .htaccess is a better way of doing things since it’s read even before Google starts loading your site. The PHP way might be a little easier to implement because it’s just a line or two of code to copy/paste whereas the .htaccess code is a little more complex.
I’d say enable the compression through the WP Super Cache plugin and go ahead and use the PHP one as well… it’s what I do.
John Hoff´s last blog ..How To Create A Category In WordPress
January 24th, 2010 at 2:42 am
Thanks John
I’ll give the “PHP in header” method a try today and check out the site in IE 6!
The “Port 8o” software is a great visual way to see those file reductions and it’s telling me that I can make some big savings.
Keith Davis´s last blog ..Ooh la la…
March 14th, 2010 at 2:08 am
Hello, do you know how I can apply this to my new blog? I opened up an account in blogspot.com. Thank you John.
SchoolPaper Addict´s last blog ..Somebody Hates Schoolwork – School Papers Suck
March 14th, 2010 at 8:50 am
No, I don’t think you can use this technique for a free hosted blog on Blogger, but try this search here for some tips on doing something like it.