Caching - pfaciana/latte-js GitHub Wiki

Caching

Caching is used for subtemplates by default - any template loaded from {include} or {extends} through getTemplate function stored in the global internal cache, unless nocache flag is provided.

Also you can store a parsed tree of any template to speed up subsequent loads:

var cache = {};

var tpl;
if ('mytpl' in cache) {
    tpl = new Latte;     //no template text in ctor
    tpl.tree = cache['mytpl'];
} else {
    tpl = new Latte('...template text...');
    cache['mytpl'] = tpl.tree;    //store parse tree
}

tpl.fetch(...);