Last active
February 1, 2018 10:11
jQuery parallel script loading keeping execution order.
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
/** | |
* Load scripts in parallel keeping execution order. | |
* @param {array} An array of script urls. They will parsed in the order of the array. | |
* @returns {$.Deferred} | |
*/ | |
function getScripts(scripts) { | |
var xhrs = scripts.map(function(url) { | |
return $.ajax({ | |
url: url, | |
dataType: 'text', | |
cache: true | |
}); | |
}); | |
return $.when.apply($, xhrs).done(function() { | |
Array.prototype.forEach.call(arguments, function(res) { | |
eval.call(this, res[0]); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment