Matt has released version 2.5 of his Staticize Reloaded. Not only has he coined a word, he’s made WordPress a heck of a lot faster!
Here’s how it works. After uploading and activating the plugin, all first-time views of a specific page on your blog will have their output cached to a file. Subsequent views will get the cached version, saving precious clock cycles on your server (which could serve static pages with its eyes closed). Whenever anything on the blog changes (post an entry, delete an entry, edit an entry, post a comment, approve a comment, delete a comment, etc), the cache is flushed, so people never see outdated versions. It caches a different version for each unique cookie-posessing visitor who visits each page. Thus, if I visit a page, I’ll get a static version that says “Welcome back, Mark!” down where the comment cookie remembers my info. The version you see will be the version based on your cookie, and thus you get a static version that says “Welcome back, YourName!”
The plugin also has support for content that should always be dynamic. If you have a script that rotates images or shows a link to a random entry, you can do this in your template to ensure that that portion will always be dynamic:
<!--mfunc function_name('parameter', 'another_parameter') --> <?php function_name('parameter', 'another_parameter') ?> <!--/mfunc-->
This way, you can turn the plugin on or off, and you get the same functionality. Similarly, you can do dynamic includes like so:
<!--mclude file.php--> <?php include('file.php'); ?> <!--/mclude-->
Matt notes that you should turn the plugin off before modifying your templates. In addition to this advice, I would recommend that you manually flush the cache as well, so everyone gets to see your tweaks. You can do this by either editing an entry and saving it (no need to make changes), or by visiting any page on your blog and adding ?staticize-flush=TRUE to the end of the URI, which will do a manual flush of your cache. After activating the plugin, expore all facets of your site, especially those that used external PHP includes or custom form submission, to ensure that they work. Then, make changes if necessary, by using the mfunc and mclude comment syntax explained above.
The performance boost given by this plugin is very impressive. I see no reason for the majority of WP blogs not to use it. One day, you might get Slashdotted and your server will thank you for being prepared.
WordPress 1.2 users: when static pages are served, there is a comment at the bottom of the source with the time it took to serve the static version. In WordPress 1.2, this is broken, and shows some huge number. In order to fix this, take out this line in wp-blog-header.php
:
if ($pagenow != 'post.php') { timer_start(); }
And add this line, in wp-settings.php
, right after require (ABSPATH . WPINC . '/functions.php');
:
timer_start();
Safety over FreedomJul 27Static, Dymanic, Fast!