Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone Marionette templateCache is not used by default?

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

like image 546
NewtonCode Avatar asked Nov 20 '13 07:11

NewtonCode


2 Answers

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.

like image 149
Robert Levy Avatar answered Nov 15 '22 10:11

Robert Levy


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

like image 29
Rayweb_on Avatar answered Nov 15 '22 12:11

Rayweb_on