-
-
Save allex/423599a745a2af1e585a8f548002478c to your computer and use it in GitHub Desktop.
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
/** | |
* 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; |
Author
allex
commented
Feb 28, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment