Skip to content

Instantly share code, notes, and snippets.

@esamattis
Last active March 6, 2020 04:43
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save esamattis/5384178 to your computer and use it in GitHub Desktop.
Save esamattis/5384178 to your computer and use it in GitHub Desktop.
/**
* Simple node.js style script loader for modern browsers
**/
function loadScript(src, cb) {
var script = document.createElement('script');
script.async = true;
script.src = src;
script.onerror = function() {
cb(new Error("Failed to load" + src));
};
script.onload = function() {
cb();
};
document.getElementsByTagName("head")[0].appendChild(script);
}
module.exports = loadScript;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment