Skip to content

Instantly share code, notes, and snippets.

@SaulDoesCode
Created May 7, 2016 19:56
Show Gist options
  • Save SaulDoesCode/cb85e8b22b15ae4baedfb3fe9acff851 to your computer and use it in GitHub Desktop.
Save SaulDoesCode/cb85e8b22b15ae4baedfb3fe9acff851 to your computer and use it in GitHub Desktop.
fetches a script and returns a promise when it's loaded
"use strict";
function GetScript(loc) {
return new Promise((resolve, reject) => {
fetch(loc)
.then(res => res.text())
.then(code => {
let script = document.createElement('script');
script.src = URL.createObjectURL(new Blob([code]));
script.onload = resolve;
document.head.appendChild(script);
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment