3 ms·
That assumes that all the changes are grouped under the same part of the tree...
by fzzzy 10y ago
That assumes that all the changes are grouped under the same part of the tree...
- trebor 10y agoSure. If you have a ton of potentially layout-thrashing changes, just clone your page's highest wrapper node. Then make your changes and replace the node. I haven't needed it, or tested it for performance, but it's clearly doable. // Example; untested pseudo-code var fragment = document.createDocumentFragment(), wrapper = document.getElementById('wrapper'); fragment.appendChild(wrapper.cloneNode(true)); // update your fragment // update the page document.body.replaceChild(fragment, wrapper); That said, because the change is to a page's entire structure I'd think the layout operation would be much slower. I'm betting React and Ember might do similar things for their "application" wrapper/scope node(s).
- RussianCow 10y agoYou also potentially lose things like focus, input text, and selection on elements that otherwise didn't need to be replaced. I'd wager that re-creating all of that would add a discernible performance cost.