influxweb
12/12/2012 - 2:40 PM

Loads a JavaScript file asynchronously with a callback, like jQuery's `$.getScript()` except without jQuery.

Loads a JavaScript file asynchronously with a callback, like jQuery's $.getScript() except without jQuery.

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);
}