Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Created March 29, 2012 03:32
Show Gist options
  • Save mxriverlynn/2232998 to your computer and use it in GitHub Desktop.
Save mxriverlynn/2232998 to your computer and use it in GitHub Desktop.
template cache
TemplateCache = {
get: function(selector){
if (!this.templates){ this.templates = {}; }
var template = this.templates[selector];
if (!template){
var template = $(selector).html();
this.templates[selector] = template;
}
return template;
}
}
TemplateCache = {
get: function(selector){
if (!this.templates){ this.templates = {}; }
var template = this.templates[selector];
if (!template){
template = $(selector).html();
// precompile the template, for underscore.js templates
template = _.template(template);
this.templates[selector] = template;
}
return template;
}
}
@DveMac
Copy link

DveMac commented Apr 10, 2012

is 'template' re-declared inside the if for a reason?

@mxriverlynn
Copy link
Author

the "var" shouldn't be there on line 7. my intention was to re-use the same template variable (which this does... its just bad form)

@mxriverlynn
Copy link
Author

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment