4 ms·
Sure. 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 hav
by trebor 10y ago
Sure. 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.