I am writing a BackboneJS application where each of the six tabs is represented by their own views. Should I save an instance of the view and just call it a function render()whenever the user clicks the tab that he has already been to? Or create a new instance and access the template that jQuery cached for me during the first rendering?
If I do the latter, I still need to make sure that the other collection is not retrieved through my JSON API, as this was done during the initialization of some views.
I currently store all instances of the view in my controller, but I was wondering if this was built in, or if there are better alternatives.
Greetings.
Update: here is my function loadCachedViewthat I use in my controller:
loadCachedView: function (name, view, collection){
if (!this.views[name]){
if (collection){
this.collections[name] = new collection();
}
this.views[name] = new view({collection: this.collections[name]});
} else {
this.views[name].render();
}
},
Therefore, in the imaging performance, I just go: this.loadCachedView('settings', SettingsView, SettingsCollcetion).
source
share