Created
June 23, 2014 13:24
-
-
Save z-------------/46ad90bbc2db0e2b83f0 to your computer and use it in GitHub Desktop.
Asynchronously load external JavaScript files
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 loadScriptAsync = function(urls, callback) { | |
| var loadedList = []; | |
| for (i=0; i<urls.length; i++) { | |
| var scriptElem = document.createElement("script"); | |
| scriptElem.src = urls[i]; | |
| scriptElem.onload = function(){ | |
| loadedList.push(true); | |
| if (loadedList.length == urls.length) { | |
| callback(); | |
| } | |
| } | |
| document.head.appendChild(scriptElem); | |
| } | |
| }) | |
| // urls - string array of script urls | |
| // callback - code to be executed after all scripts are loaded |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment