Skip to content

Instantly share code, notes, and snippets.

@adrianjguerrero
Last active September 9, 2020 03:19
Show Gist options
  • Save adrianjguerrero/2169a503d095acca2d574c8610f4e6a9 to your computer and use it in GitHub Desktop.
Save adrianjguerrero/2169a503d095acca2d574c8610f4e6a9 to your computer and use it in GitHub Desktop.
useful for when you need to get a very large svg and don't want to put it inline because it makes the page load very slow
const getSvg = async (svgUrl, svgContainer) => {
let request = await fetch(svgUrl)
let svgText = await request.text()
const parser = new DOMParser();
const svgHtml = parser.parseFromString(svgText, "text/html");
svgContainer.appendChild(svgHtml.body.querySelector('svg'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment