Created
February 27, 2017 22:14
-
-
Save pseudosavant/81fd60585f23f6d257af9378febc5ea8 to your computer and use it in GitHub Desktop.
Basic script loader in JavaScript with optional callback on `load`
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
// Loads an external js file and optionally calls a callback on completion | |
function loadScript(url, callback) { | |
var script = document.createElement('script'); | |
document.body.appendChild(script); | |
if (typeof callback === 'function') { | |
script.addEventListener('load', callback, false); | |
} | |
script.src = url; | |
return script; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment