-
-
Save robcolburn/4356237 to your computer and use it in GitHub Desktop.
How jQuery.getScript should work!
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
function getScript (src, callback) { | |
var scripts = document.getElementsByTagName('script'); | |
var script = document.createElement("script"); | |
var once = true; | |
script.async = "async"; | |
script.type = "text/javascript"; | |
script.src = src; | |
script.onload = script.onreadystatechange = function () { | |
if (once && (!script.readyState || /loaded|complete/.test(script.readyState))) { | |
once = false; | |
callback(); | |
} | |
}; | |
scripts[0].parentNode.insertBefore(script, scripts[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment