Skip to content

Instantly share code, notes, and snippets.

@afcapel
Created December 16, 2022 16:55
Show Gist options
  • Save afcapel/845e135a1d2fe1d0072b0feb322ec905 to your computer and use it in GitHub Desktop.
Save afcapel/845e135a1d2fe1d0072b0feb322ec905 to your computer and use it in GitHub Desktop.
Slow document.body.cloneNode(true) in Chrome
<!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