Created
December 16, 2022 16:55
-
-
Save afcapel/845e135a1d2fe1d0072b0feb322ec905 to your computer and use it in GitHub Desktop.
Slow document.body.cloneNode(true) in Chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Slow document.body.cloneNode(true) in Chrome</title> | |
<body> | |
<div id="container"></div> | |
<script type="text/javascript"> | |
let container = document.getElementById("container") | |
const cloneBody = () => { | |
const start = new Date().getTime() | |
console.log("Cloning...") | |
document.body.cloneNode(true) | |
const elapsed = new Date().getTime() - start | |
console.log(`Cloned in ${elapsed}ms`) | |
} | |
for (let i =0; i < 10000; i++) { | |
container.insertAdjacentHTML("beforeend", ` | |
<div> | |
<form method="post" class="test"></form> | |
<button onclick="cloneBody()">Clone body</button> | |
</div>`) | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment