Created
October 31, 2018 00:04
-
-
Save jochemstoel/efbadd0bd4756386616fc9ae0b5c924e to your computer and use it in GitHub Desktop.
JavaScript: loadScripts
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
| // Loads js files | |
| function loadScripts(urlArray,cb) { | |
| var scriptLoadCount = scriptLoadedCount = 0; | |
| loadScript(); | |
| function loadScript() { | |
| var head= document.getElementsByTagName('head')[0]; | |
| var script= document.createElement('script'); | |
| script.type= 'text/javascript'; | |
| var url = (urlArray[scriptLoadCount].indexOf('?') == -1) ? urlArray[scriptLoadCount] + '?d=' + Math.random() : urlArray[scriptLoadCount] + '&d=' + Math.random() | |
| script.src= url; | |
| head.appendChild(script); | |
| scriptLoadCount++; | |
| script.onload = function() { | |
| scriptLoadedCount++; | |
| if (scriptLoadedCount < urlArray.length) loadScript(); | |
| else if (cb) cb(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment