Skip to content

Instantly share code, notes, and snippets.

@jzeltman
Created June 13, 2019 13:26
Show Gist options
  • Save jzeltman/627f1f4cda01cb278fa90b638b232ec5 to your computer and use it in GitHub Desktop.
Save jzeltman/627f1f4cda01cb278fa90b638b232ec5 to your computer and use it in GitHub Desktop.
loadScript.js - JavaScript Script Loader Utility Method
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