Thaya Kareeson has written an excellent article for plugin developers. It goes through how to make plugins work with WP Super Cache by using dynamic AJAX calls.
WP Super Cache can make static html copies of pages served by WordPress which is great for performance. Unfortunately that means some plugins don’t work because they rely on executing PHP on each request. The plugins need to be rewritten to use AJAX calls by the visitor’s browser. There’s a FAQ in the readme.txt all about it!
I previously wrote about adding AJAX to WordPress plugins but Thaya has worked through a simple example that will work perfectly with WP Super Cache. It’s a good foundation for plugin developers start from.
He also has versions of WP Postviews and Popularity Contest that have been rewritten to support static caching. I haven’t tried either plugin so leave a comment on his blog if you need help!
If you depend on a large portion of your content being dynamic this isn’t the solution for you as it will affect what search engines see. Those bots don’t speak Javascript, but for interactive purposes (ratings, stats etc) it’s the job.
- AJAX in Plugins is a must-read starting point for developers.
- wp_enqueue_script() is the command WordPress uses to load Javascript files. That page links to a couple of good pages too including this best practices post. As of this writing, Thaya’s example don’t use wp_enqueue_script() but it’s simple to use.
The vast majority of plugins work just fine with WP Super Cache, but some of the ones that don’t are quite popular. If your favourite plugin doesn’t work, why don’t you help the author out and fix it? You have all the source code after all and you’ll be helping everyone else who uses the plugin!
I actually just had to do this exact thing for a contract gig. The client was using WP Super Cache and could not figure out why WP-Postviews wasn’t updating on refresh. I fixed it with AJAX, just like the author above.
I have updated the fix into the core code sometime ago. I tested it, it did count the hits.
Gamerz – that’s great to hear. I should update the readme!
Thanks for writing about my post Donncha.
I wrote it because I still cannot use WP Super Cache on my site because of Who Sees Ads and a few other plugins. I would make them compatible myself, but there is definitely no time to do it all myself.
I was hoping that I can help urge all plugin developers make their plugins WP Super Cache compatible and I can eventually reap the rewards.
Couldn’t a similar method be used to eliminate the need to have separately cached pages for each logged in user?
It certainly could but in most cases the number of anon users vastly out numbers the number of logged in ones so there wouldn’t be much of a performance gain.
In recent versions of the caching plugin the number of cache files has been reduced dramatically too.
There is also a plugin out there called Widget Cache that can be used by folks.
Since WP Super Cache is very popular plugin and very useful, I am working on improving my GD Star Rating plugin to support it. Rating already works (partially at least, votes are saved), but is not always displayed right. This post is good starting point to add cache support.
Thanks for this info, I’m sure all the developers will include it in their plugins as many users use WP Super Cache
very nice how-to, thank you for the information about it.
I love wp-super-cache. You helped me survive a big traffic spike yesterday. I looked for a donate link on your site but could not find one.
Just wondering what the other plugins are that this plugin doesn’t work with. I have installed super cache but on a recommendation from someone. I haven’t actually done my due diligence on how to make sure it works properly. I just was concerned about my site loading faster.
Thanks,
Lisa
Lisa – plugins that update the page based on user interaction may not work. I’d say most plugins will work just fine.
Android – check the supercache page, there’s a big donate link there and on the admin page too!
Wow, I wish I had googled this last week it would have saved a headache! Thanks for the links to the articles and the information.
All the best
Leanne 🙂
Sorry im not very newbie in php but what is ajax? from where can i learn something about this programmin language? and can you advise me some books name related to ajax? thanx
Excellent! That’s exactly what we need. As someone new to blogging, I’m afraid to use a caching plugin for that very reason. I don’t know how to tell what it will break.
Couldn’t a similar method be used to eliminate the need to have separately cached pages for each logged in user?
I use the “More Fields” plugin, which lets me add a “File List” Custom Field to my Add/Edit Post pages. The “File List” control works by issuing an AJAX request to “/wp-content/plugins/more-fields/more-fields-write-js.php?post_id=xxx&…”, but that request fails when WP Super Cache is enabled — even when I explicitly add “more-fields-write-js\.php” to list of strings not to be cached.
Here’s why: at the time the AJAX request is made, I have to be logged in, and the effect of being logged in causes WP Super Cache to append the string ‘‘ to the AJAX result, which effectively mangles the JSON string being returned.
My solution was to rearrange a couple of tests being performed in wp-cache-phase2.php, so that it *FIRST* checks “if (!in_array($script, $cache_acceptable_files) && wp_cache_is_rejected($wp_cache_request_uri))” *BEFORE* it checks “if ( $wp_cache_not_logged_in && is_user_logged_in() && !is_feed() && !is_admin() )”.
This simple change insures that anything I explicitly block from being cached won’t be modified either. This allows “More Fields” to work properly, and it allows me to easily fix any other incompatible plugins that I might run into.
If this change is safe enough to incorporate into WP Super Cache, that would be ideal — or if you have a better solution, even better. In any case, thanks for a great plugin!
I’ve written a small plugin that automates most of this process for you, so you can take almost any plugin function and ‘ajaxize’ it. No need to be a programmer or mess around with javascript. For more info see http://blog.gingerlime.com/ajaxizing