Backbone Marionette templateCache is not used by default?
Asked Answered
D

2

6

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 :)

Decortication answered 20/11, 2013 at 7:15 Comment(0)
M
2

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.

Medico answered 20/11, 2013 at 22:41 Comment(1)
thnx for your answer.it helped me. somebody else did it..i dont know whyDecortication
U
1

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

Upswell answered 20/11, 2013 at 7:31 Comment(3)
so that means , by default marionette does not make use of template caching?Decortication
No, saying its built in it means that is already there not that is used by default.Upswell
It is used by default and without you needing to explicitly reference itMedico

© 2022 - 2024 — McMap. All rights reserved.