Skip to content

Instantly share code, notes, and snippets.

@JustinTulloss
Created October 19, 2010 06:33
Show Gist options
  • Select an option

  • Save JustinTulloss/633720 to your computer and use it in GitHub Desktop.

Select an option

Save JustinTulloss/633720 to your computer and use it in GitHub Desktop.
Injecting template versions
// By just injecting a script tag, we can version the template and exploit the cache
function loadTemplate(template, version) {
var src = '/media/bujagali/' + this.name + '.' + this.version + '.js';
var headEl = document.getElementByTag('head')[0];
var script;
script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
headEl.appendChild(script);
}
// Calling this on mytemplate.js with version 319abd18760971243856681f40939fd8 returns this (generated) code
Bujagali.fxns['mytemplate.html'] = function(ctx, args) {
var self = this;
function emit(more) {
Array.prototype.splice.apply(
self.markup,
[self.markup.length, more.length].concat(more));
}
emit('<h1>Hello World</h1>');
};
Bujagali.fxns['mytemplate.html'].version = "319abd18760971243856681f40939fd8";
Bujagali.fxnLoaded('mytemplate.html');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment