Loading your templates from external files is awesome.
Loading your templates only moments before they're needed is even awesomer.
$.tmpload('search', 'path/to/search.tmpl');
$.tmpload([ { name: 'search', url: 'path/to/search.tmpl' }, { name: 'comments', url: 'path/to/comments.tmpl' } ]);
These templates haven't downloaded yet (that's a good thing).
$('#search').focus(function(){ //They're probably about to search, so... $.tmpload('search'); });
The search template is now downloaded and cached in the background.
$.when( $.tmpload('search'), $.getJSON('path/to/data.json') ).then(function(tmpl,data){ $.tmpl(tmpl,data).appendTo('#target'); });
The template is now loaded from the cache.
If the template isn't already cached, it is downloaded immediately and saved for later.
© 2011 Mark Dalgleish. This plugin is released under the MIT License
Follow me on Twitter! @markdalgleish