Optimizing Movable Type's Standard Templates for Speed (part 2)

| 1 Comment | No TrackBacks
In the previous article in this series I talked about how you can set publication of certain templates to 'Manually' to speed up publishing of your blog.  Today will discuss setting up caching and server side includes, and the reasons for using them.  The first reason is pretty important: if you don't use them the sidebar(s) on most of your Movable Type blog will constantly be out of date if you are using the default templates.
Why is your sidebar out of date?

This has to do with Movable Type's static publishing model.  In the default template set, the templates that determine the look and content of your archives (category, monthly, entry...) are only used to produce actual HTML files at the time when entries (or comments) are added that would affect these HTML files.

In other words, if an entry or comment gets added today in the category 'Sports', the archive page for February 2007 or the category page for 'News' will not be changed.

Normally, this is great: only updating the pages that need an update makes things go faster, and faster is better, right?  But what about sidebars?  By default, your sidebar might include things like recent comments, a list of your archives, a list of your categories (with the number of entries in each category) and many other things.

Most of this stuff is included through the 'Sidebar' template module, which in turn includes one or more widgets via a widgetset.  But because of the static publishing model, the sidebar is included only at the time of publication and remains 'frozen' ever after, until a new publication takes place.

And that is why your archives from two years ago still contain the most recent comments from two years ago and an overview of your categories as they were back then.

How to solve this?

You could republish your entire blog after each entry you publish.  (Don't laugh, I know people who do this).  But this is horribly inneficient and can take a very long time on blogs with hundreds or thousands of entries.  Not only do you have to publish tons and tons of HTML pages, but for each page that includes the sidebar Movable Type needs to recalculate the entire contents of it, over and over again.

So obviously it is not the way to go.

If only there was a way to calculate certain content only once, and to include it on all pages but serve it from a single source so it stays up to date everywhere.

Well, actually there is such a way...

Module caching and server side includes

In the settings of your blog you will see this option:

settings.jpg

Depending on what type of Server Side Includes are possible on your server, pick the one that works on yours and enable module caching.  (If no Server Side Includes are allowed on your server, just leave it off.  Your sidebars etc. will unfortunately remain out of date until you republish the entire blog.  But at least it will go a bit quicker thanks to Module Caching if you follow the next steps.)

Next, open Design > Widgets in your blog's menu.  Check the widgets that you are using in your sidebar(s) and open them one by one.  At the bottom of each one, you will see a 'Template Options' block that you can click open:

templateoptions.jpg
 
Now follow these steps:
  1. Does the content that this widget produces need to stay up to date in your archives etc?, and will it be the same everywhere?  If the answer is 'Yes', check the box to process it as an include.
  2. Does this content ever change?  If no, set the caching options to expire after x minutes (or hours)...
  3. If the content does change, set the cache to expire upon creaton or modification of whatever causes the changes...
For example, on this blog I am using the 'Search' module in my sidebar.  This will basically never change during the lifetime of this blog, unless I am totally restyling it.  So I have set it to be cached for 30 minutes.

I am aso using the 'Recent Comments' widget, which I have set to be processed as an SHTML include and to be cached until a new comment comes in.  The same goes for my 'Category' and 'Monthly Archives' widgets, only these are cached until a new entry is added to the blog.

The result

Entries and comments on this blog are published just a bit quicker since most of the contents of the sidebar now only need to be calculated once, instead of separately for the main page of the blog, the individual page with the entry, the category archive of the entry, the monthly archive of the entry...

Also, the parts of the sidebar that need to be up to date everywhere on this site (recent comments, montly archives, list of categories with number of entries in them) are up to date everywhere, all the time.

No TrackBacks

TrackBack URL: http://www.movabletips.com/cgi-bin/mt/mt-tb.cgi/33

1 Comment

Module caching good way to make faster blog. I used it. SSI is next step.

Leave a comment