I can detect when an array of deferred AJAX requests are finished using jQuery, and I can detect when the page loads using jQuery.
But I can't seem to detect both at the same time.
Here's what I've got:
$(function () {
var getscriptlist = ['js/libs/handlebars.js', 'js/libs/ember.js', 'js/libs/prefixfree.js'];
var deferreds = [];
for (var i = 0; i < getscriptlist.length; i++) {
deferreds.push($.getScript(getscriptlist[i]));
}
$.when.apply($, deferreds).then(function () {
});
});
But I want the AJAX requests to run before the page starts loading, and then I want to fire something when the document has loaded as well.
My current problem is that the page loads, and the AJAX will take too long, as it starts running only after the page loads. If I switch it the other way round (so that the requests are fired, and when they're done and the page has loaded), then maybe the AJAX requests take too long, and delay the execution of scripts on the page, which bind to inside the $(function
, which is run when the page finishes loading.
Any help? Thanks.