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.)