The main template template matrix is ​​not used by default?

According to Derik 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 template1 in the template cache for the first time and subsequently access it from the cache? I have this doubt, because when I check the global TemplateCache object, it is not actually stored. Am I missing something?

Each time a template is selected from the DOM? (Derik even says that choosing a DOM is expensive)

I am new to Marionette. Any help would be really appreciated. Thanks:)

+6
source share
2 answers

Bt, by default, Marionette will read the DOM element and run it through the underscore function template () to compile the html template into a simple JS function. This function is used in the template cache. Take a look at the annotated source code available on the puppet website to see how it works and where you can connect to make a difference.

+2
source

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 the var template 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 this template, one form will be used in which the cache will be used.

so you first need to use the templatecache object from the puppet to compile / save the template

+1
source

Source: https://habr.com/ru/post/958447/


All Articles