Visits to this blog

Dojo’s DTL performance gains with HtmlTemplate

I’ve recently discovered (and greatly appreciated) the performance gain to be found with switching to using Dojo‘s Django Templating Language’s HtmlTemplate class.

I was previously using the standard dojox.dtl.Template class, which writes textual HTML, and sets the innerHTML property of a node. While this worked relatively well on Firefox and Safari, on IE 6 and 7, it performed like a snail, mostly due to IE’s terrible DOM performance.

Neil Roberts has written a DOM-based template generator for Dojo 1.2 (currently in the nightlies) that solves this nicely. Instead of writing to the innerHTML of a DOM node, and overwriting the template each time, it generates the nodes just once, and reuses them each time.

For repeated operations, the speed up is amazing – I found that it generated large templates up to four times faster in Internet Explorer, with smaller gains in more up to date browsers like FireFox and Safari.

It also greatly reduces the chances of memory leaks – which are a real problem if you are dealing with innerHTML.

I’ve updated my search site, Chofter.com, with Neil’s latest code, and it’s running much quicker than before. Neil has also updated his blog, someclosure.com, with the latest code.

Hopefully with the release of Dojo 1.2 (any day now….), Neil should have a good amound of docs and demos to show people how to get the most out of dojox.dtl – it really is a fantastic piece of software.