Don't Ignore Movable Type's <mt:ignore> Tag

| 2 Comments | No TrackBacks |
When faced with a Movable Type blog that is sometimes slow to publish, you could immediately break out the heavy guns and set up some performance logging to try and find out which templates are taking too long to publish.  There is an entire section of the documentation dedicated to this.  But before editing configuration files and starting to pore over logfiles, don't ignore the humble <mt:ignore> tag...
This tag is basically the equivalent of commenting out a section of template code in Movable Type, a bit like using <!-- and --> in HTML source code which tells the browser to ignore a certain part of the HTML it is trying to display.

HTML comments vs. MT:Ignore
Note that you can also use these HTML escape codes in Movable Type templates, and the end result will look the same visually.

Compare:

Foo
<!--Bar-->
Bla

Foo
<mt:ignore>Bar</mt:ignore>
Bla

Both will result in 'Foo' and 'Bla' being displayed.  The main difference is that the source code for the first bit will still contain the escape codes and the word 'Bar'.  Publishing both snippets of template code will also take about the same amount of time.

Difference
But what if instead of just the word 'Bar' we comment out an <mt:include> tag which brings in a complex template module that takes a long time to publish?

Foo
<!--<mt:include name="Bar">-->
Bla

Foo
<mt:ignore><mt:include name="Bar"></mt:ignore>
Bla

In this case, there is a clear difference.  Publishing the first snippet will take considerably longer than the second snippet.  Even thought the output is not displayed, the first snippet will still include and process the entire module, while the second snippet won't even 'see' the include tag and will skip it completely, resulting in much quicker publication.

Using this for debugging slow templates
You can use this in combination with Movable Type's 'Preview' function on the template editor to quickly 'drill down' into a page  to see which parts are taking unusually long to publish.  The best thing is, you don't even need to save any changes as you work so you can do this on a live site as long as you are careful not to hit the wrong button.

Let's look at a quick example.this is the main index template for this blog:
preview0.jpg

If I hit the 'Preview' button at the bottom I get a screen that shows me what the page will look like should I publish it.  More importantly, at the top of this screen I also get some information about how long it took to publish this page:

preview1.jpg

One point three seconds, not too bad.  But what if I comment out the main <mt:entries> loop, just for fun?  Let's have a look:

preview2.jpg

Note: here I have to be careful to hit 'Preview' and not 'Save Changes' or even 'Save & Publish'.  The result (i.e. my main page without the entries) looks like this:

preview3.jpg

OK, so not much to look at, I admit.  But what I am most interested in is this:

preview4.jpg

Zero point fourteen seconds...  That means the entries take up the bulk of the time needed to publish this page.  (It also means my sidebar is optimized really well.)  If I wanted to optimize this page further, I would now start looking into the 'Entry Summary' module that was between my <mt:ignore> tags to see where further improvements could be made, but since this page already publishes reasonably fast I won't bother here.  Generally speaking, any template publishing in under one or two seconds is fine, it is the ones that take more than that you need to worry about.

One tip though: once you start optimizing includes, you either have to start saving the included modules as you edit them (else the changes won't show up in the preview) or you could simply copy-paste their contents into the 'main' template and keep on 'Preview'-ing as you <mt:ignore> your way through them to identify the slow spots.

No TrackBacks

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

2 Comments

Great tips Maarten... I'm considering about changing to Movable Type from Wordpress after hearing quite a few positive things about it. Do you think it would be worth it or should I just stick to what I have learned with WP?

Leave a comment