3 ms·
> Wouldn't it be much more efficient to create a view just > once by setting innerHTML, and then update it using the > DOM (setting attributes, classe
by jashkenas 14y ago
> Wouldn't it be much more efficient to create a view just
> once by setting innerHTML, and then update it using the
> DOM (setting attributes, classes, innerText, etc.)?
Funnily enough, it usually isn't. Especially in older browsers, where performance matters most -- setting a single innerHTML call with a bunch of HTML is far cheaper than doing the equivalent number of DOM-twiddling operations.
While it's entirely possible with Backbone views to listen to specific change events and only modify the smallest possible portion of the DOM, it's usually not worth the bother -- appropriately coarse-grained template renders are both more convenient and faster.