Swap element "in-place" with replaceWith() vs .outerHTML (version: 0)
Swap an DOM element with replaceWith() and compare with the .outerHTML method of replacing its content instead.
replaceWith()
- Pretty one-liner
- Breaks element attributes, inline style and scrollHeight/scrollWidth (fully re-render element)
.outerHTML
- Keeps attributes, inline style and scrollHeight/scrollWidth (partially re-render element)
- Breaks previous element references, "hacky" looking and sometimes perceptible (element may flash for a split second)
Comparing performance of: replaceWith() vs .outerHTML
Memory measurements supported only in Chrome.
For precise memory measurements Chrome must be launched with --enable-precise-memory-info flag.
More information: Monitoring JavaScript Memory