Skip to content

Instantly share code, notes, and snippets.

@tombowers
Last active August 29, 2015 14:08
Show Gist options
  • Save tombowers/a861163176a5f8d9db13 to your computer and use it in GitHub Desktop.
Save tombowers/a861163176a5f8d9db13 to your computer and use it in GitHub Desktop.
Load Cross-Domain Javascript Synchronously Using jQuery
$.getScript('http://example.com/script1.js', function () {
alert('Script Loaded');
});
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!');
});
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