Optimizing Movable Type template modules: include a file instead of embedding content

|

Suppose you have MT blog which uses the tags plugin. And suppose you have a sidebar on every blog page which uses the tags. And the sidebar is on every page.

Now the humanly natural thing to do here is to place the tag-related code into sidebar module which gets included into every page. Which is fine mostly. Except if you have lots and lots of tags. Say just only tens or so. Because soon you’ll notice that category rebuilds start to waste massive amounts of time and soon end up in 500 Internal Server Errors. You think there’s a bug in your code which can also cause this, you go over all the entries and templates… nothing.

Apparently, MT groks when it has to rebuild and reiterate over the same stuff too much, and this throws some sort of timeout or resource overrun or whatever.

The solution is simple. Think of it. The code is the same and its results do not change across rebuilding different pages. So why run it over and over for each page? It makes sense to abstract the code into a separate index template, and the module can just include that index template file with MTInclude as a regular file.

This can rid you of those 500 Errors and massively improve rebuild times. So before going to bash the tool for being slow, go look in the mirror. With or without MT, optimizing your code and template structure can make a MASSIVE difference.

Leave a comment