Blosxom Hybrid Mode
ComputerStuff
A (long) while back, I posted to the Blosxom mailing list about the idea of running Blosxom in a “hybrid” mode, where the cgi was still active, but most pages were served from static html files. The idea is to combine the best of both worlds (dynamic and static modes):
By serving from static html files, server load and time to load a page are dramatically decreased. Most of the time, running a cgi script to serve what is essentially static content is a waste. When you load a page in a fraction of a second that used to take 5 seconds to create, it feels pretty good.
By continuing to run the CGI, however, you still have access to interactive plugins - comments/writebacks, searching, etc. So you aren’t missing out on these features.
The downside:
- Many blogs rely (too much, IMHO) on super-dynamic content that changes each time you load a page. This can’t be effectively done using a hybrid mode. I would argue that much of this dynamic content could be done away with, but that’s a separate discussion. For example, I used to have a calendar in my sidebar that would show the LatestNews from the current month. For this to work, I would have to regenerate every page on the first of the month, or it would not work properly. If I added an entry, I would have to update every page in order to update the calendar. I decided this was not worth it, and removed the calendar from the sidebar, and added a link to the year view instead. You may decide that you are not willing to lose such features, in which case this approach is not for you.
I moved away from Blosxom, and began using OddMuse, but some of the same concepts still applied, and I really wanted a hybrid mode. So I wrote the Static Hybrid Module, which accomplished what I was looking for. In fact, it is in use on this site - almost all pages are served from static XHTML files that are updated whenever a change is saved. I have not done any formal testing, but I would seriously doubt there is a faster Oddmuse site out there than this one, unless they are also using the hybrid mode.
I saw a story on Douglas Nerad’s site that got me thinking about this all over again, so I experimented a little bit with my idea about a hybrid mode for blosxom, and this is what I came up with.
Server Setup
You need access to the Mod_Rewrite module for Apache, or something similar for this to work. You need to set up your .htaccess file similar to this:
Options -Indexes
DirectoryIndex blosxom.cgi index.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteRule ^(.*)$ /blosxom/blosxom.cgi/$1 [L,QSA]
In this case, the /blosxom
directory of my web site is where the hybrid version will reside. This means the cgi script needs to be there (ok, technically not, but it makes sense to do it), and the static files will need to be here as well.
You configure your blosxom setup as per usual, but make sure that the output from the static mode goes to the /blosxom
directory of your site (or whatever directory you chose).
How it Works
Before you do anything, it behaves like a normal blosxom site, with the “hide the cgi bit” trick enabled. You can check out my bare bones install as an example:
When you visit this site, it is served by the blosxom cgi in the usual way.
But once you run the static mode, it pregenerates pages for the whole site within the /blosxom
directory. The next time you visit, you are served the content of these pages, without the blosxom.cgi script being run.
If a requested page or directory doesn’t exist, then it is passed to the blosxom cgi to handle the request – again, in the usual way. This allows dynamic only features, such as the find plugin to work. There isn’t much content on my site, but the search feature works.
Possible Pitfalls
There are many plugins that behave differently in static and dynamic modes (including some of mine…) I suggest that you test this carefully before relying on it for any important websites to ensure that the behavior is as expected.
Whenever you add or update a story on your blosxom weblog, you need to regenerate the static copies. I understand that some of the gui tools can do this automatically.
Also, plugins that modify the site (comments, writebacks, etc) will have to be modified so that they either regenerate the affected pages, or they could also delete those pages, causing the cgi script to take over.
I would also recommend setting up a cron job to regenerate the site every so often, just to fix any glitches that arise.
If you rely on the hide, login, or exclude plugins you will need to double check their behavior to ensure they work properly. The login plugin will be difficult to use…
Plugins that rely on submitting information (typically those that submit forms) will have to submit that data to the root URL, NOT to a particular page - for example http://blah.com/blog/?find=query is ok, but http://blah.com/blog/index.html?find=query is not. The second version will pull up a static page, which of course doesn’t handle CGI parameters.
Notes
This page is a work in progress, I welcome comments and additions!