Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function getScript(source, callback) {
var scriptElement = document.createElement('script');
var priorScriptElement = document.getElementsByTagName('script')[0];
scriptElement.async = 1;
scriptElement.onload = scriptElement.onreadystatechange = function( _, isAbort ) {
if (isAbort || !scriptElement.readyState || /loaded|complete/.test(scriptElement.readyState) ) {
scriptElement.onload = scriptElement.onreadystatechange = null;
scriptElement = undefined;
if (!isAbort) {
if (callback) {
callback();
}
}
}
};
scriptElement.src = source;
priorScriptElement.parentNode.insertBefore(scriptElement, priorScriptElement);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.