Speed Up WordPress WITH or WITHOUT a WordPress Cache

WordPress Although using a plugin that caches WordPress is the best overall solution, I can't use any of them with the way I run this blog. I did the research, tried the hacks, and ended up falling flat on my nose. I'll explain what I finally ended up doing after I list the options.


WordPress Caching Plugins

There are a few plugins that work well. There may be more, but these are ones I know about. I'll try to keep it all in order and add notes and links.

WP-Cache 2.0

This is probably the one that started it all. It was abandoned by the author on [it looks like] October, 24, 2007 when he abandoned his blog. The only way to enable compression with it is to enable zlib.output_compression in the php.ini (if you have access to it) and disable the compression inside of WordPress (not included in the current version anyway). The latest version of WP-Cache still works with WordPress.

WP-Cache NoSymlink

This is exactly like WP-Cache except that it works on servers where symbolic links can't be used or accessed.

1 Blog Cacher

Based on WP-Cache and HTML Cache Creator, it's been around for about 10 months (as of today's date). I haven't tested it and have no desire to do so. It's compatible with WordPress up to 2.2 and I'm well past that point.

WP Super Cache

This is WP-Cache on steroids. It supports compression immediately on install and serves .htaccess-driven static files as well as the WP-Cache-type files. Which files get served depends on cookies. If you have the zlib compression in your php.ini enabled, you have to disable it in order to use the built-in compression.

Hyper Cache

This plugin does not rely on the existing code of WP-Cache in any way. I tested it. It servers static, uncompressed files, though compression can be used through the php.ini just like WP-Cache.

Dynamic Code

All of the listed caching plugins, except for Hyper Cache, use the mclude and mfunc conventions. WP Super Cache uses it for the regular cache part, but not the super cache part, which is understandable because no php code is executed in true static files.

A lot of people don't know how to use the conventions, but I spent some time testing them. If you do something like this:


<--mclude testfile1.php-->
<?php include 'testfile1.php' ?>
<!--/mclude-->

The cache plugin will change the middle line to <?php include_once('testfile1.php'); ?> regardless of what you put there. Your original line will execute prior to being cached and the substituted line will be executed when the file is loaded from the cache.

If you don't inlcude testfile1.php in the first line, the code in the middle will remain untouched. The mfunc works in the same way, except with functions.

My Own Speed Up Solution

With all the plugins available, I decided not to use any of them and use something that previous versions of WordPress used: On the fly compression. The reason is strictly because of the Google AdSense ads.

I use code to prevent Google AdSense ads from showing to anyone but search visitors. If I use WP Super Cache, regardless of which caching method I use, the cached page is based on the first person to load the page. If the first person doesn't see ads, neither will the search visitors that follow him or her until that page has expired in the cache. On the other hand, if the first search visitor sees ads, the next non-search visitor will see the ads until that page has expired from the cache.

In this case, the cache defeats the purpose of conditionally displaying the AdSense. Setting the cache to expire quickly doesn't help. The dynamic code I mentioned above doesn't work with my conditional code unless I rewrite it for that purpose and it still only works for the non-super cache part of the plugin. In my opinion, having dynamic code within a cached page kind of defeats the purpose of the cache anyway.

I enabled on the fly compression by inserting ob_start("ob_gzhandler"); just above /* Short and sweet */ line in the main index.php for the blog. I also enabled on the fly compress for my CSS file by changing the link in the header.php file to style.php after inserting the following code at the top of my style.css file and saving it as style.php. [Warning: I was suspended on shared hosting for using this due to the CPU spikes.]


<?php
ob_start ("ob_gzhandler");
header("Content-type: text/css; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 1440;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>

The Future

The problem with displaying Google AdSense ads conditionally using JavaScript itself is that it's against their Terms of Service. It would solve my caching problems. I understand I can send them email and get permission to use the modified code, but I haven't written it yet. Once I write it, I'll be sure to make it available for everyone to use (with Google's permission, of course).

If I decide to stop displaying AdSense ads to search visitors as well as everyone else, the issue will resolve itself. That day is far in the future, however, as this is my primary online income at the moment.

More Notes

I only wrote about caching and compression. There are other ways to speed up a WordPress blog that I won't get into at this time. The short version is that you have to reduce queries, function calls and HTTP connections.

I have only one question. Are there any brilliant JavaScript programmers out there that can figure out how to write conditional JavaScript WITHOUT altering the AdSense code (including the script tags)?

(Update: I worked with the author of Hyper Cache to create two separate cache files; 1 for search visitors and 1 for non-search visitors. I am now using both the "on the fly" compression and Hyper Cache.)

Similar Posts:

27 Comments

  1. hari says:

    I myself don't bother about such issues because I don't think I get the traffic to justify having to "speed up" my website and secondly the server I'm hosted on is a very good one and doesn't host too many other sites.

    irregardless…

    Minor gripe — there's no such word. Regardless it is.

    At least it shows I'm reading your posts though :razz:

    My latest blog post: Boxi and Panjo – Farewell to Thee

  2. Gavin Smith says:

    Very interesting read, thanks for putting in the work and sharing this with us.

  3. Gavin Smith says:

    Yah but if your anything like me you love the programming right, almost as enjoyable as blogging.

  4. hi RT, I've noticed a couple of times over the last day or two that when I checked Untwisted Vortex I would get a blank white page. A few minutes later it would load as normal. I'm wondering it this was during your testing and was what you described as "falling flat on my nose". ~ Steve

  5. Yeah! I also know that solving a programming problem is also enjoyable as blogging.

  6. [...] each other's comments and interrupt the flow of good discussions. I found this article on speeding up Wordpress without a cache, but the only way I can know if it works is to disable WP-Super-Cache, implement that solution, [...]

  7. Don says:

    We are getting ready to start developing in Drupal but we have been researching the differences between Drupal an WordPress and the effects of CSS with both… Can anyone provide any feedback between the pros and cons of each? Thanks!

  8. I just want to share WordPress benchmarks with and without WP-Cache. Clean WordPress on 2.6Ghz dual core P4 with 1Gb of RAM with Linux, can give only 3.44 requests per second. After WP-Cache installation score was 235 requests per second. If you have ability to install APC, you can double throughput and server could serve 467 requests per second.

  9. Frank from laptop review says:

    can i actually use this code on my blog? are there any downside i should know before applying it??

    My latest blog post: How to add a Send Link button in Google Chrome

  10. Peter from Reading Speed Test says:

    Thanks for your tips. I've always been thinking how to make all my BLOGs response faster.

    My latest blog post: Online Reading Comprehension Test is Launched

  11. bobby says:

    this article is marvles and i cant even rate it!!!!!! a bigggggggggg thanks to the author…

  12. Bryan says:

    I can use this info to make my wordpress load faster.

    My latest blog post: Penis Advantage Review

  13. Nice article. I was looking for the same solution.

    My latest blog post: Fat Binders for Weight Loss

  14. quad says:

    Thanks a lot for this article. Now my wordpress blog is going so fast… but I choosed the non-cache option.

    My latest blog post: Endurance de 24 heures non stop !

  15. Thanks for the article – one newbie question though: will wp-supercache work ok with google adsense if you're NOT using any conditional displays for the ad (i.e. if your page will always display the ad) – a bit nervous about breaking adsense terms and conditions!

    Thanks again!

    My latest blog post: Invitation to Write Articles for Wonkie

  16. This is great! Sometimes I'm using Wi-fi in the nearby cafe and can be really slow online connection. I hope this will help! Thank you!

Leave a Reply

CommentLuv Enabled

This site uses KeywordLuv. Enter YourName@YourKeywords in the Name field to take advantage.

Anti-Spam Protection by WP-SpamFree