According to Derick Bailey in one of his posts , Template Cache Built In To Backbone.Marionette
So when i specify a template like this
Backbone.Marionette.ItemView.extend({template : '#template1'});
Does it really store the template template1 into template cache the first time and access it from cache subsequently? I have this doubt because when i inspect the global TemplateCache object , it is not actually being stored. Am i missing something?
Is the template being selected from DOM each time? (Derick even says DOM Selection is expensive )
I am a new to Marionette.Any help would be really appreciated.Thanks :)
Bt default, Marionette will read the DOM element and run it through underscore's template() function to compile the html template into a simple JS function. This function is what goes in the template cache. Take a look at the annotated source code available on the marionette site to see how this works and where you can plug in to change things.
According to the documentation https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.templatecache.md when you do this
var template = Backbone.Marionette.TemplateCache.get("#my-template");
inside your template var you will have a compiled template but at the same time this template will be stored in the cache, so the next time you use that template the one form the cache will be used.
so you first need to use the templatecache object from marionette to compile/ store the template
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With