Created
January 29, 2024 07:56
-
-
Save ryanmorr/21f143615cab7e805145108b943ed0c8 to your computer and use it in GitHub Desktop.
Parse an HTML string into a document fragment
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
const cache = new Map(); | |
const template = document.createElement('template'); | |
function parseHTML(html) { | |
if (cache.has(html)) { | |
return cache.get(html).cloneNode(true); | |
} | |
template.innerHTML = html; | |
cache.set(html, template.content); | |
return cache.get(html).cloneNode(true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment