In the following code snippet, do i need to cache $(“#loading”) in another object (lets call it JqueryDOMCache) or Backbone does this for me? I want to make the app performant as I have 300 odd DOM interactions.
var BeforeApploadView = Backbone.View.extend({
el : "#loading",
render : function(){
$(this.el).show();
},
hide : function(){
$(this.el).hide();
}
});
var App = (function($){
var app = {};
app.start = function(s){
var beforeLoadView =new BeforeApploadView();
beforeLoadView.render();
};
return app;
});
No, you do not need to do anything special. There are two reasons for this:
BeforeApploadView, then it has a reference toelso that it stays alive.hidefunction does not remove the elmenet from the DOM. It only appliesstyle="display: none"to the element. The DOM keeps a reference to the element as well.You should be all set.