Created
May 7, 2016 19:56
-
-
Save SaulDoesCode/cb85e8b22b15ae4baedfb3fe9acff851 to your computer and use it in GitHub Desktop.
fetches a script and returns a promise when it's loaded
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
"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