-
-
Save 0xDaksh/384af6911e702397ca7315ac08f91672 to your computer and use it in GitHub Desktop.
Loads a JavaScript file asynchronously with a callback, like jQuery's `$.getScript()` except without jQuery.
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
function j(u, c) { | |
var h = document.getElementsByTagName('head')[0], s = document.createElement('script'); | |
s.async = true; s.src = u; | |
s.onload = s.onreadystatechange = function () { | |
if (!s.readyState || /loaded|complete/.test(s.readyState)) { | |
s.onload = s.onreadystatechange = null; if (h && s.parentNode) { h.removeChild(s) } s = undefined; | |
if (c) { c() } | |
} | |
}; | |
h.insertBefore(s, h.firstChild); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment