tmpload

Asynchronous Template Loading and Caching
for jQuery Templates

download tmpload<1KB minified

Loading your templates from external files is awesome.

Loading your templates only moments before they're needed is even awesomer.


Declare one template

$.tmpload('search', 'path/to/search.tmpl');

Or declare groups of templates

$.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).


Load and cache intelligently

$('#search').focus(function(){
  //They're probably about to search, so...
  $.tmpload('search');
});

The search template is now downloaded and cached in the background.


Ready when they need it

$.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

Fork me on GitHub