Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function loadScript(src, fn) {
var script, done, head;
script = document.createElement('script');
script.src = src;
script.async = true;
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) {
done = true;
script.onload = script.onreadystatechange = null;
if (fn) {
fn();
}
if (script && script.parentNode) {
script.parentNode.removeChild(script);
}
}
};
if (!head) {
head = document.getElementsByTagName('head')[0];
}
head.appendChild(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment