Skip to content

Instantly share code, notes, and snippets.

@E01T
Created July 13, 2013 07:16
Show Gist options
  • Save E01T/5989765 to your computer and use it in GitHub Desktop.
Save E01T/5989765 to your computer and use it in GitHub Desktop.
Dynamic, cross-browser script loading - from head.js lib
// From the headjs code:
function scriptTag(src, callback) {
var s = doc.createElement('script');
s.type = 'text/' + (src.type || 'javascript');
s.src = src.src || src;
s.async = false;
s.onreadystatechange = s.onload = function() {
var state = s.readyState;
if (!callback.done && (!state || /loaded|complete/.test(state))) {
callback.done = true;
callback();
}
};
// use body if available. more safe in IE
(doc.body || head).appendChild(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment