Created
June 13, 2019 13:26
-
-
Save jzeltman/627f1f4cda01cb278fa90b638b232ec5 to your computer and use it in GitHub Desktop.
loadScript.js - JavaScript Script Loader Utility Method
This file contains hidden or 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
function loadScript(src, done) { | |
let js = document.createElement('script'); | |
js.src = src; | |
js.onload = function() { | |
done(); | |
}; | |
js.onerror = function() { | |
done(new Error('Failed to load script ' + src)); | |
}; | |
document.head.appendChild(js); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment