recipeswithbackbone / recipeswithbackbone.github.com

Marketing site for the best damn backbone.js book evar
23 stars 1 forks source link

Template Caching Examples #15

Open chrislawlor opened 12 years ago

chrislawlor commented 12 years ago

One page apps should take as much advantage of browser caching as possible. Various tutorials recommend implementing templates in such a way that they can be cached - but I've yet to see any concrete examples, or any sort of real world evidence (even anecdotal) that caching templates would offer any performance benefit. I suppose the benefit depends on the size / complexity of the templates, but still, it would be nice to see some possible approaches.

I haven't experimented with this yet, since I'm currently generating templates dynamically server side, but if there were some evidence of a performance benefit, I could rework them to be static.

In a similar vein, it might be worthwhile to devote some pages to discussing loading assets dynamically, to lessen page load times for an empty cache. This isn't necessarily a backbone specific technique, but it would be nice to see some examples of this in the context of a backbone app.

ngauthier commented 12 years ago

@chrislawlor definitely some cool problems in there, but like you said I'm not sure how they would fit in with the book.

If I had to take a crack at it, I'd put the template into its own JS file, then reference the template from the view file. That way if the files are served separately the browser will cache the file as a whole. Or if asset packing is being used on the project then it doesn't matter because the templates will be bundled into the rest of the code.

AFAIK templating is not a common performance sink, and backbone pretty much says "do your own templating".

I'm interested in this problem but it will not be addressed in 1.0.