Is Your Wordpress Slow Loading? Make It 3 Times As Fast In Under A Minute

file-size-zlib-wordpress-compression

With one line of code, you can speed up Wordpress to 3x as fast loading than before. By doing this, you give any reader the content you have written at a faster rate, giving them less of a chance to click the back button. This reduces your bounce rate (which I’m going to write about in a future post) and increases visitor interaction and conversion. Why wouldn’t you want this on your blog?

A quick note about the methods used: If you are currently using Gzip, this will not work in conjunction with one another.

UPDATE: [Oct 15th, 2009] – This technique is compatible with WP Super Cache.

zlib Compression for Wordpress

zlib Compression in a nutshell takes Wordpress code (the php to be exact) and compresses it before sending it to the visitor’s internet browser. The compressed file is then sent to the browser for it to be decompressed and displayed for the user. This process is much faster than just sending the uncompressed data to the browser which uses more bandwidth and is slower to load. The zlib compression will work with all the new major browsers and causes no compatibility problems to the older ones.

Making Sure that zlib Compression is Enabled:

To find out if zlib has been enabled on your web host, simply create a new file in Notepad (Or Notepad++ which is what I use) and paste the following code into the document:

<?php phpinfo(); ?>

Then simply uploading the file to your server and loading it in your browser will show whether you have zlib compression enabled or not. It can be found under a heading called, “zlib”.

Alternatively, if you know that zlib compression is enabled you can skip this step.

The Code:

This code needs to be placed in the header of the document, at the very top of the code – even before the DOCTYPE. (Due to Wordpress’s annoying feature that strips the beginning PHP comment out of the post, please type <?php before you paste the code below)

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

Then update the header file and you should instantly notice a difference… I know I did!

Check your zlib compression efficiency:

Simply go to http://www.port80software.com/support/p80tools.asp to check your compression factor, percentage and the number of bytes saved.

Conclusion:

I referenced this post for the process and exact code on how to do this, I felt that this would be interesting for anyone with a blog. What inspired me to write this post was WPBlogHost’s post on Gzip compression, although I found out that my web hosting doesn’t support it!

Remember – Too fast is never a bad thing :)

Do you use any plugins or customized code to make Wordpress load faster?

This entry was posted in Tutorials and tagged , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Enjoy this post? Theres more to come, so click here to subscribe to our RSS Feed.

41 Comments

  1. Posted October 15, 2009 at 2:53 am | Permalink

    I was just wondering about two things:

    1) Since PHP is server-side, why send it to the client? I’m not sure that’s what you meant to say? :)

    2) What are the downsides of using this script/method? I’m sure there must be *some* downside, otherwise it would be enabled per default. Or is it only the fact that gzip/wp-cache might not work?

    • Posted October 15, 2009 at 2:53 pm | Permalink

      Hi Klaus,

      1) It compresses what the PHP outputs (eg – HTML) in Wordpress. Perhaps I should of made that more clear :)

      2) There is no downside.. It might just be the fact that some web hosting doesn’t have this enabled, so theme developers skip this little tweak to maximize usability.

  2. Posted October 15, 2009 at 12:22 pm | Permalink

    Hi Brad, thanks for the link. It’s nice to know you have options when one method won’t work.

    I love tweaking WordPress with these sorts of things. As far as plugins go, I pretty much just use the WP Super Cache to speed things along, it works very well.

    I noticed you had mentioned zlib compression won’t really work if you use the WP Cache plugin, maybe that’s one difference between using gzip and zlib? Right now I’m using gzip to compress my data and WP Super Cache doesn’t seem to mind.

    • Posted October 15, 2009 at 2:56 pm | Permalink

      Hi John.

      Not a problem – If I didn’t visit your site in the first place, I wouldn’t of known about this tweak :)

      Hmmm.. I just assumed that it wouldn’t work with static HTML files, due to the way that it compresses PHP output. I could be wrong..

      What did you find?

  3. Posted October 15, 2009 at 12:23 pm | Permalink

    I hadn’t thought of enabling zlib compression for WordPress, thanks for the informative article!

    What I use on my blog both to speed it up and to reduce traffic is the WP Super Cache plugin. It’s great for when you get a traffic wave from Digg.com, as it caches your WordPress pages and loads a static HTML on every visit, instead of executing long PHP requests.

    • Posted October 15, 2009 at 3:05 pm | Permalink

      Glad you liked it Dimitar,

      I’m actually going to test the WP Super Cache plugin with this script.. I’ll most likely update it with the results.

      There’s nothing more discouraging then getting a front page article on Digg, then having your server crash under the load.

  4. Posted October 16, 2009 at 2:28 pm | Permalink

    Hi Brad,Thanks for sharing this information, I tried it on my blog and got the positive result as well. Yes, it is compatible with WP Super Cache and worked fine for me. Bookmarked the page as well.

    • Posted October 16, 2009 at 7:26 pm | Permalink

      Hi Sanjeev.

      Glad to hear it! When its combined, WP Super Cache and this code make Wordpress very fast. :)

  5. Posted October 23, 2009 at 2:05 pm | Permalink

    Works like a charme!

  6. Posted October 24, 2009 at 1:26 pm | Permalink

    Also if you remove any disabled plugins from your wp-content/plugins folder it speeds it up quite a bit. Every little bit helps. Has anyone else found it runs super slow on Windows?

    • Posted October 25, 2009 at 6:08 pm | Permalink

      I’m running Windows XP… Think it loads pretty quick.

      Are you sure it isn’t your computer that runs slow, or your web hosting?

      Great tip about the plugins.. didn’t think about that.

  7. Posted October 30, 2009 at 12:55 pm | Permalink

    I’ve used these plugins in the past before on bloggin-ads, but there are always problems. It may be faster for the visitor, but much slower for the owner.

    -Mike
    Free Arcade Games´s last blog ..Hey Wizard My ComLuv Profile

    • Posted October 31, 2009 at 8:35 am | Permalink

      Hi Mike,

      I don’t think this technique is a plugin, but if your talking about WP-Super Cache, then I’m not sure about your circumstances… It really helps DIGG-Proof my blog!

      Nice to see you here again! :)

  8. Posted November 2, 2009 at 1:00 am | Permalink

    Have you tested the impact of using compression rules on the .htaccess file (perhaps vs this PHP compression)? I’m interested because unnecessary PHP slow page creation and put load on your host and I like to keep the WP theme as light as possible. Of course one call isn’t that much (especially when highly useful like this one), but if the same can be done on the server level without PHP call, it’s always better…

    Note that WP Super Cache does turn on compression for the HTML files it caches, but compressing CSS, JavaScript, images, etc. needs additional .htaccess rules. If your host supports mod_deflate, that does a great job, but the older mod_gzip is OK too.
    Antti Kokkonen´s last blog ..Analyzing the State of the Blogosphere 2009 My ComLuv Profile

    • Posted November 2, 2009 at 12:36 pm | Permalink

      I haven’t tried compression through a .htaccess file… would you happen to know how to do that? I’d be glad to write another post based on that if it compresses CSS and Javascript as well. They can get really big, really quickly – especially if you are customizing your template.

      • Posted November 2, 2009 at 2:07 pm | Permalink

        In short, the mod_deflate compression is used like this (as said, requires that mod_deflate is in use on your host, and not mod_gzip):

        AddOutputFilterByType DEFLATE text/html text/javascript text/css application/x-javascript

        I actually written a post couple of weeks ago where I collected the best optimization related htaccess rules, including compression: The Most Essential .htaccess Rules For Blogs

        • Posted November 2, 2009 at 2:24 pm | Permalink

          WOW – That’s an awesome post! Information overload (in a good way).

          Thanks for the link.. I will be trying many of the techniques out. :)

  9. Posted November 3, 2009 at 8:33 am | Permalink

    Hey thanks for the great article! Got 80% improvement in the loading of the site!
    Gautam´s last blog ..After the Deadline – Spell Checker Plugin for bbPress! My ComLuv Profile

    • Posted November 3, 2009 at 4:16 pm | Permalink

      You sped up your Wordpress loading speed by 80%? That’s incredible! :) I’m really glad you could take advantage of this tutorial!

  10. Joseph
    Posted November 13, 2009 at 4:28 pm | Permalink

    Hi Brad,

    I’ve confirmed my host has zlib enabled and added the code to my header.php file as per your instructions but the compression check tells me it’s not enabled!

    Any idea what I might have done wrong?

    Cheers
    Joseph

    • Posted November 13, 2009 at 5:23 pm | Permalink

      Hi Joseph,

      The tool needs to be refreshed.. IE – Clear your cookies for it to recognize the changes.

      If you’ve already done that, send me an email and I’ll be glad to help you out.

      Thanks!

      • Posted December 9, 2009 at 4:46 am | Permalink

        Hey Brad,

        very nice post here. Appreciate it.
        I have the same problem that Joseph had.
        I copied the code like you mentioned and then uploaded my new header file.
        But even after deleting my browser cache and after deleting my cookies and reloading the p80tools website to check my status, it tells me that my site status is uncompressed.

        I checked zLip with phpinfo and it tells me it is enabled.

        Do you know what else can be wrong?

        Best regards
        Daniel Neubauer – Webprogrammierer und Front-End-Developer

        • Posted December 9, 2009 at 6:42 pm | Permalink

          Hey Daniel,

          Glad you enjoyed the post.

          Could you install YSlow and let me know if the result is still the same?

          Perhaps the robots.txt is not allowing the Port80 bot to download your header correctly?

          Feel free to get back to me.

  11. gcod
    Posted November 16, 2009 at 8:05 pm | Permalink

    Weird I get an error but my host has zlib:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /blog/wp-content/themes/tata/header.php on line 13

    Any Idea?

    • Posted December 9, 2009 at 6:43 pm | Permalink

      Try replacing the quotes with the regular ‘ ones.. I think Wordpress formats it with a “beautified” version of a standard code quotation.. That sounds like the problem your facing.

  12. Posted December 12, 2009 at 11:04 pm | Permalink

    Hi Brad,

    Could you look into my website? My VPS host says it is enabled and I have added zlib code on the website but that header checking website still shows ‘uncompressed’..

    • Posted December 13, 2009 at 4:10 pm | Permalink

      Hey Sid.

      Took a look at your website, it is still uncompressed.

      I’ve fixed the code, I think I know whats causing the problems..

      Could you repaste the code into your header?

      Thanks!

      • Posted January 13, 2010 at 11:28 pm | Permalink

        Hey Brad,

        Really sorry for not getting back to you on time and luckily have bookmarked this website now :) And, I did add the code but it showed uncompressed.. So, later I used this code in htaccess file and it worked for a while :( Don’t know why did it show uncompressed after an hour..

        php_flag zlib.output_compression on
        php_value zlib.output_compression_level 2

        And, the last thing I did was enabling ’super cache compression’ in wp super cache plugin.. now the files are ‘compressed’ although I don’t know which one is the better.. zlib or super cache compression? :)

        Thanks for the help!
        Rockstar Sid´s last blog ..Another Free Maxim Magazine Subscription For 2010 My ComLuv Profile

  13. Sushil
    Posted December 14, 2009 at 12:41 am | Permalink

    Hi Brad

    I m new for wordpress or joomla, I just want to learn how it work on net, first of i want to test on my system, so please tell me how i configure wordpress on local system.

    I m using wampserver on my system, is it possible to work wordpress on wampserver? Please give me some example link, I m expecting for mail

    Thanks

  14. Posted December 16, 2009 at 9:42 pm | Permalink

    Having the same problem as Daniel/Joseph/Sid…any update on possible solutions?
    Jouke´s last blog ..Twitter’s New Office My ComLuv Profile

    • Posted December 17, 2009 at 1:11 pm | Permalink

      Hi Jouke,

      Perhaps you already have it set in the PHP.INI or the .htaccess? If both are set to compress using either Gzip or Zlib (they cannot be used in conjuction) it would result in it being sent uncompressed. Do you have access to those files?

      Thanks.

      • Posted December 21, 2009 at 9:13 pm | Permalink

        Brad,

        Its definitely not in my .htaccess file. Couldnt find my php.ini, although a search on google said that shared hosting accounts on Hostgator (which is what i am using) don’t have access to it.
        Jouke´s last blog ..Twitter’s New Office My ComLuv Profile

  15. Posted December 19, 2009 at 8:55 am | Permalink

    Having WP Super Cache but did not try the zlib Compression yet. So far less traffic so no issue. ;)
    Jayce´s last blog ..How to hack Facebook account profile My ComLuv Profile

  16. Posted December 30, 2009 at 5:37 pm | Permalink

    Hi Brad
    Found your site via your comments on John Hoff’s site.
    I was going to implement his gzip compression method but thought better of it when John told me that it may cause problems with IE6 and below.
    Interesting that you have written a post “Are You Missing Out on 14.24% of YOUR Website Conversions?” about IE6.

    You say that “The zlib compression will work with all the new major browsers and causes no compatibility problems to the older ones”
    Does that mean that I can use zlib and not have problems with IE6?
    Keith Davis´s last blog ..The eyes have it! My ComLuv Profile

    • Posted December 31, 2009 at 6:11 pm | Permalink

      Glad you liked the article Keith!

      I know that IE6 has gzip compression problems, as do the earlier versions of the program. This code will only compress your content if the browser sends the header tags that it “will” accept zlib/gzip compression. I do not believe that IE6 and previous send those tags, so to answer your question, you can use zlib and not affect IE6 users.

      Happy New Year :D

  17. Posted December 31, 2009 at 1:50 pm | Permalink

    Thanks Brad
    That’s good news.
    I’ll give it a try and hopefully report back with a super fast blog.

    Happy new year – have a great 2010
    Keith Davis´s last blog ..The eyes have it! My ComLuv Profile

  18. Posted December 31, 2009 at 2:04 pm | Permalink

    This is really educational. Thanks, Brad. I will be looking into it.

    For Bloggers Who want to Stop Writers’ Block

  19. Posted January 1, 2010 at 8:07 am | Permalink

    Hi Brad
    I uploaded the file with “” and got lots, and I mean lots, of info about my hosts PHP setup, but what in particular should I be looking for?

    If I simply add the zlib code to my header and find that it doesn’t work… presumably I can simply remove it without causing any problems.
    Keith Davis´s last blog ..Ooh la la… My ComLuv Profile

    • Posted January 1, 2010 at 10:56 am | Permalink

      Yeah, the PHPINFO command usually does that.. It displays everything PHP related to you!

      Look for a section with the header “zlib” – In that section it should say “enabled”, if you cannot find it, contact me and I’ll take a look. :)

  20. Posted January 1, 2010 at 11:48 am | Permalink

    Hi Brad
    Found it and it says… enabled.
    Will add the code to header later and test on the “port80″ software.
    Keith Davis´s last blog ..Ooh la la… My ComLuv Profile

3 Trackbacks

  1. [...] Brad Blogging Skip to content AboutContact BradAdvertiseWhat Is R.S.S and Why Subscribe To Us? Rss Feed Email Subscriptions Email Me Skype Anyone? « Is Your Wordpress Slow Loading? Make It 3 Times As Fast In Under A Minute [...]

  2. [...] 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 [...]

  3. By Eco Friendly Wordpress - and Super Fast on December 18, 2009 at 8:54 am

Post a Comment

Your email is never published nor shared. 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>

CommentLuv Enabled

626 RSS Subscribers

Subscribe today to recieve any updates on this blog for free!

You'll also receive, "The Blog Manual" free of charge for being a subscriber which you can download at the bottom of each post.

 


Blog Advertisers

About The Author

Brad Ney

I am a Wordpress enthusiast, part-time website designer, and enjoy using the latest technology via the internet for website promotion.I enjoy writing about startup websites, XHTML, CSS, Wordpress based on what I've learned in the industry.

Become A Facebook Fan!

Reader Poll

  • Are you a...

    View Results

    Loading ... Loading ...

Recent Comments

  • Jayce: Long time did not optimize my blog already. Does this speed up a lot? .-= Jayce´s last blog ..How to...
  • JR @ Internet Marketing: Just became a fan! .-= JR @ Internet Marketing´s last blog ..The Ultimate and Best...
  • Sadia Malik: Hi, Thanks for the tips, I browsed the internet for some ready made templates but they dont quite seem...
  • recklessbliss: Hi, thanks for the info but I’m still at a loss about what exactly C.S.S. framework is. Your...
  • Gomez the windshield monkey: Brad, Nice tip. I find I struggle with this, though. For me, this is advanced PHP...

Leave A Comment - Reap The Rewards

  • CommentLuv will fetch your last post - Free publicity!
  • NoFollow Removed - Free backlink from each post you comment on!
  • Choose to be notified of replies made to your original comment!
  • Share your prospective while learning new things and have fun meeting the community.
  • Have a question? I answer every comment with a personal response.