Created
October 19, 2010 06:33
-
-
Save JustinTulloss/633720 to your computer and use it in GitHub Desktop.
Injecting template versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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