Dramatically Speed Up WordPress/WPMU Load Times With This Simple Tip!

December 10, 2009  | 
43 Comments

050514-F-7203T-005.JPGWho doesn’t want lightning fast page delivery? Is your WPMU site operating at a painfully, embarrassingly slow speed? People are impatient when it comes to site load times and will often leave if it takes longer than two seconds to see the page. The information available to internet users is increasing exponentially and people have no time to waste on slow loading websites. Optimizing your WordPress blog for speed is a serious matter of competition for the attention of your user. The faster you can serve your pages, the better chance you have of lowering your bounce rate. This small piece of code will take you less than a minute to paste into your site and can instantly have your site running approximately 3-4 times faster than before. It’s called zlib compression.

What is zlib Compression?

zlib is a lossless data-compression library that will help you to serve your pages faster. Basically it compresses the PHP that WordPress sends to your visitor’s browser so that it displays much more quickly. Compressing and sending is much faster than sending the PHP in its full size format. Believe me, you will love it.

How do I use it?

Step 1:

First, do a quick check to make sure that zlib is enabled on your server. Paste this into a text file, save as it test.php, and upload to your server:

<?php phpinfo(); ?>

Visit your test page and it should display everything you ever wanted to know about PHP running on your server. Scroll down until you find the zlib header and check to see if it’s enabled. If it is, then you can proceed to the next step. If zlib isn’t enabled, Twitter Tools & Apps, contact your host. I can’t guarantee that they will enable it for you, but the change in speed is so significant that it’s worth a try.

Step 2:

Add this small bit of code to the header.php file of your theme. Place it directly above your doctype at the beginning of the file.

<?php
ini_set(’zlib.output_compression’, ‘On’);
ini_set(’zlib.output_compression_level’, ‘1);
?>

Update the file and the change should be instant. You will probably notice it even before you use tools to test the output. I recently tested zlib with one of my WPMU sites and it helped me to serve my pages 3.5 times faster than before compressing- an unbelievable improvement! You can check your compression factor at: http://www.port80software.com/support/p80tools.asp. It will tell you if compression is working on your site and the percentage and number of bytes saved, as seen below one of my sites.

speed

I first learned about it from Brad Ney in his helpful post. It’s important for you to know that this technique is compatible with WP Super Cache, which is a plugin that I highly recommend for anyone running WPMU. It causes your blogs to serve static html pages to the majority of your visitors, specifically those who are not logged in, have never left a comment or have never viewed a password-protected post. This plugin can really save the day if you or any of the bloggers on your WPMU network have a post that gets a lot of attention and you experience a sudden spike in traffic. If your server can’t handle that amount of traffic, you can cause a crash during what ought to be your shining moment. Get your site prepared before this happens. If you’re using shared hosting that is completely oversold and overloaded, this plugin will also give you an instant boost.

These speed-enhancing methods are not just WPMU-compatible but will dramatically increase the speed of a single-user WordPress blog as well. You may not be able to afford higher quality hosting, but now you may not have to. These tools should improve your site’s load time with any host. They are also compatible with all major browsers, even the ancient ones. Combine zlib compression with WP Super Cache and you are on the road to a super fast loading site!

Featured Plugin - WordPress + Google Maps = Perfect

Simply insert google maps into posts, sidebars and pages - show directions, streetview, provide image overlays and do it all from a simple button and comprehensive widget.
Find out more

Featured Plugin - Easily integrate your WordPress site with Facebook

Would you like to add Facebook comments, registration, 'Like' buttons and autoposting to your WP site? Well, The Ultimate Facebook plugin has got that all covered!
Find out more

Featured Plugin - Every great SEO tweak you need, in one snazzy bundle

Fully integrated with the SEOMoz API, complete with automatic links, sitemaps and SEO optimization of your WordPress setup - this is the only plugin you need to help you rank your site number 1 on Google - nothing else compares.
Find out more

Featured Plugin - Turn any WordPress page into a fully featured wiki!

To get a wiki up and running you used to need to install Mediawiki and toil away for days configuring it... not any more! This plugin gives you *all* the functionality you want from a wiki, in WordPress!!!
Find out more

Featured Plugin - Send beautiful html email newsletters, from WordPress!

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

Featured Plugin - Add bottom corner (or anywhere else) chat to your site

No javascript required, no third part chat engine, just fully featured chat right in your own database on your own WP sites - couldn't be easier.
Find out more

Featured Plugin - Open an Online Store with MarketPress

Out of all the WordPress ecommerce plugins available, this has got to be the winner - easy to configure, powerful functionality, multiple gateways and more. A simply brilliant plugin!
Find out more

Featured Plugin - Start Your Own Powerful Membership Site

If you're thinking about starting a paid, or just private, membership site then this is truly the plugin you've been looking for. Easy to use, massively configurable and ready to go out of the box!
Find out more

Featured Plugin - Host sites, get paid, just like WordPress.com

If you've ever wondered how you could offer a paid site management and hosting service, then this is the plugin for you. Offer a freemium or paid service, for any niche you like, it's powered Edublogs.org to success already!
Find out more

43 Responses to Dramatically Speed Up WordPress/WPMU Load Times With This Simple Tip!

  1. great tip, my host won’t change settings on the server as it will effect other sites. Thanks any way

  2. Is there anyway to do this side wide?

  3. John McLear.. you could put the code in a global header plugin and put the code in there.. I think that should work!

  4. Will – If your host can’t enable zlib, you may try compressing with gzip instead. It does basically the same thing.

  5. “Basically it compresses the PHP that WordPress sends to your visitor’s browser”

    ***If your server is sending PHP to browser your WPMU won’t be working so well.

  6. I checked the PHP info on my WAMPServer on my machine and the zlib info checked out so I inserted the snippet of code at the very top of the header.php file. Ended up with a screen full of gobbledy-gook. Don’t know offhand what the problem is there, may have something to do with other PHP settings or just because it’s a Windows server.

    Then I tested it out on a site that I have hosted elsewhere (running on a Linux server) and it worked perfectly.

  7. Hey Sarah – Thanks for the reference!

    I’m glad you found that useful – I know I sure did… I’m currently enjoying a 3x page loading improvement.

    Its a shame though that my web host hasn’t enabled gzip! Or I would of been sending .CSS and .JS files compressed as well. :D

  8. I too am wondering how you would implement this on a WPMU with over 100 themes (without having to place the code in each theme manually, and again, each time the themes are updated). I have tried two WPMU global header plugins but to no avail. Also does it matter if WPMU is installed via a subdirectory?

    Thanks!

  9. ^Disregard *Noob alert*…

    I answered my own question, just gzipped my entire site and that took care of the subdirectory (duh) install.

    Amazing results!

    Original size: 25980 bytes

    Compressed size: 7530 bytes

    Savings in bytes: 18450 bytes

    Percentage saved by compression: 72.0%
    Transfer speed improvement: 3.4 X
    ———————————————
    Here’s what I added to my .htaccess file (my top-level .htaccess, not the WPMU .htaccess)

    #BEGIN SITE COMPRESSION#

    # compress all text and html:
    AddOutputFilterByType DEFLATE text/html text/plain text/xml

    # Or, compress certain file types by extension:

    SetOutputFilter DEFLATE

    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

    #END SITE COMPRESSION#

  10. Excellent! Glad you have seen such an improvement! Thanks for posting your method.

  11. Thanks for the tip.

    Also, with WP Super Cache, is there any way to check if its incompatible with certain plugins? I have so many plugins installed, I don’t know what might break with WP Super Cache.

  12. I tried this but get the error on a white screen:
    parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /[...]/header.php on line 11

    I checked and zlib is enabled on my server.

    Any idea why this could be? Thanks for your help.

  13. Oh, and line 11 where there is supposedly an error is:
    <meta http-equiv="Content-Type" content="; charset=” />

  14. Kunal – that’s weird. If you copied and pasted the code in there, it’s possible that the single quotes were pasted in the wrong format. Delete the single ticks and then manually enter them from your keyboard – if that makes sense. ;) WordPress formats it strangely when I post the code so that quotes don’t paste right.

  15. Hey Sarah,

    Manually copying it seemed to work. Thanks!

  16. nicely put there Sarah.
    Hopefully It helps people out there and thanks for pointing the compatibility with Super cache plugin.

  17. Wow, I can’t thank you enough for this extraordinarily helpful tip, Sarah! We got a 78% compression and 4x improvement in load times!

    You have become a must-read for me every day now. Thank you, thank you, thank you.

  18. Some hosts, like ourselves, consider ini_set to be a security risk since you can execute global variables if it’s enabled. Use at your own risk if you have your own VPS or Dedi!

  19. Sarah,

    That was a terrific tip; thanks for doing it.

  20. Superb stuff! Thank you so much for this awesome little hack, works like a charm!

    I too had to change the little ticks ( ‘ ) individually as I got the (parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /[...]/header.php on line 11) error but once I changed it – wow.

    I cannot thank you enough.

    Please if you get a moment Sarah, hop on board Freelancer Unplugged too if you freelance at all :D

  21. Pingback: 5 Quick Tweaks To Improve Your Wordpress Blog

  22. great. i have to try it. thank you anyway :)

  23. Help i can not get it to work i get this

    Fatal error: Call to undefined function phpini_set() in /home/beachbiz/public_html/wp-content/themes/Greengo/header.php on line 1

  24. Hi Sarah
    I took a look at Brad Ney’s article on using zlib and then found your article.

    Your article has clarified a few issues… such as setting up the “test.php” to check for zlib and placing the code in the header PHP “Place it directly above your doctype at the beginning of the file”

    Having read both articles I should be able to give it a go.

  25. Super. If it doesn’t work you can always try gzip compression which is pretty similar.

  26. Hi Sarah
    We should both be out celebrating on New Year’s Eve… but I can’t get away from this keyboard. Sad!

    I was thinking of using gzip but John Hoff explained that it can cause problems with IE 6 and older browsers.
    http://wpbloghost.com/blog/gzip-compression/

    Happy New Year – have a great 2010

  27. Any help for this?

    Help i can not get it to work i get this

    Fatal error: Call to undefined function phpini_set() in /home/beachbiz/public_html/wp-content/themes/Greengo/header.php on line 1

  28. Ed Morgan – probably your issue is that you need to replace the single quotes in the code I posted. It probably pasted in a formatted way. Just go through and delete each tick and type it in manually, if that makes sense.

  29. Yes i read that from your other post that did not work.

  30. Thank you!
    This works perfectly !

  31. Consider defining the rules on a .htaccess files as it will compact css files as well.
    Your header.php is just not good enogh.

  32. Simple yet very effective tip, thank you.

  33. Just like Ed, it doesn’t work on my site, although I’ve replace the (‘) manually. :(

    Fatal error: Call to undefined function phpini_set() in /home/…/header.php on line 1

  34. Adding this along with wp super cache wont really add any benefit.

    This compresses php, as where wp super cache serves html. It might just be my morning blues though :S

    Its one of the things i love about php though :P

  35. What a quick, dramatic improvement – thank you! You’ve made me an instant subscriber.

  36. I have checked to see if this was enabled and it say yes… I talke with host gator and they said the code needs to go in the php.ini file and not the header.php of the theme.. .

    i have wordpress MU installed and would like to do this also… not sure what code or where to past now… they said the sytax of the code in this article would not work in a php.ini file…

    help apprecaited.. thanks

  37. Im having problems with this. I followed the instructions. It says zlib is enabled. So i added that code at the top of the header. As soon as i upload that file I am not able to see the site anymore. I get a blank screen :S
    Please help :)
    Thanks!

  38. Hey, thanks for posting this :) Worked great for me !

  39. What if I don’t have a header.php file? I’m using Genesis Framework.

  40. Thanks for the tips it really works with me..

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting