I have several scripts I need to dynamically include in a specific order. I have looked at and tried several answers here: How to include multiple js files using jQuery $.getScript() method
My problem is that the answers here either don't work in my application due to loading the files asynchronously or greatly over complicating the matter due to loading external scripts. The scripts I need to dynamically load are internal. (ie: On my site's server)
In addition to many other attempts, Ive tried:
$.when(
$.getScript('/1.js'),
$.getScript('/2.js'),
$.getScript('/3.js'),
$.getScript('/4.js'),
$.getScript('/5.js'),
$.Deferred(function (deferred) {
$(deferred.resolve);
})
).done(function() {
//Do Something
});
but this does not load the scripts in proper order and kicks out a slew of errors.
Furthermore, The scripts I need to load are internal and I dont see the need for all the AJAX
Ive also tried other variations to no avail and was hoping someone could illustrate how I could dynamically load internal scripts one after another, preferably without AJAX calls and over complicating?
$.getScriptcalls calls in the callback of each previous one. Are you using SPA architecture for the site? I ask as I'm trying to determine the reason for async loading of scripts; it's usually a lot more hassle than it's worth.