Created
December 22, 2017 17:25
-
-
Save sebworks/fca25b261834c367a39da5b151984961 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var scripts = []; | |
var src; | |
var script; | |
var pendingScripts = []; | |
var firstScript = document.scripts[0]; | |
function stateChange() { | |
var pendingScript; | |
while (pendingScripts[0] && pendingScripts[0].readyState == 'loaded') { | |
pendingScript = pendingScripts.shift(); | |
pendingScript.onreadystatechange = null; | |
firstScript.parentNode.insertBefore(pendingScript, firstScript); | |
} | |
} | |
while (src = scripts.shift() ) { | |
if ( 'async' in firstScript ) { | |
script = document.createElement('script'); | |
script.async = false; | |
script.src = src; | |
document.head.appendChild(script); | |
} | |
else if ( firstScript.readyState ) { | |
script = document.createElement('script'); | |
pendingScripts.push(script); | |
script.onreadystatechange = stateChange; | |
script.src = src; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment