Skip to content

Instantly share code, notes, and snippets.

@yuanqing
Forked from esamattis/loadscript.js
Last active September 13, 2015 03:42
Show Gist options
  • Save yuanqing/ded9bdc843de40831485 to your computer and use it in GitHub Desktop.
Save yuanqing/ded9bdc843de40831485 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