Forked from jnrbsn/gist:4268258
Created
November 22, 2017 09:19
Star
You must be signed in to star a gist
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