DEV Community

Discussion on: Javascript DOM Manipulation to improve performance

Collapse
 
alephnaught2tog profile image
Max Cerrina

The only trick to remember is that when building DOM up imperatively, you should always build a detached tree first, then apped the fully constructed tree to the document.

Why? I'm assuming it's because a smaller tree traverses faster, yeah?

Collapse
 
_developit profile image
Jason Miller 🦊⚛

Mutating a disconnected tree is cheaper than a connected one because it has no chance of causing side effects like layout. So you build up the largest possible disconnected tree, then "commit" all those mutations by attaching its root.