Last active
August 29, 2015 14:08
-
-
Save tombowers/a861163176a5f8d9db13 to your computer and use it in GitHub Desktop.
Load Cross-Domain Javascript Synchronously Using jQuery
This file contains 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
$.getScript('http://example.com/script1.js', function () { | |
alert('Script Loaded'); | |
}); |
This file contains 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 aryScripts = ['http://example.com/script1.js', 'http://example.com/script2.js', 'http://example.com/script3.js']; | |
loadAndExecuteScripts(aryScripts, 0, function () { | |
alert('All Scripts Loaded!'); | |
}); |
This file contains 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
function loadAndExecuteScripts(aryScriptUrls, index, callback) { | |
$.getScript(aryScriptUrls[index], function () { | |
if(index + 1 <= aryScriptUrls.length - 1) { | |
loadAndExecuteScripts(aryScriptUrls, index + 1, callback); | |
} else { | |
if(callback) | |
callback(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment