I am working on js script loading techniques and want to show a custom loader while all my content/resources are loading. Below is working as far as I can tell to load js scripts in order but my web app is throwing some errors after it starts.
My question is: how is the below script (which is called as a <script> right after jQuery at the bottom of my HTML) different from simply having all these js scripts called as <script>'s in the head of the HTML? Why errors on one but not the other?
$(document).ready(function(){
jLoader(scripts[0]);
});
var i = 0;
function jLoader (script){
return $.ajax({
method: "GET",
dataType: "script",
url: script,
context: document.body,
cache:true,
}).done(function() {
console.log(script + ' loaded!');
step();
}
});
}
function step(){
i = i + 1;
jLoader(scripts[i]);
}
var scripts = ['js/materialize.js','http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js','js/leaflet.awesome-markers.js',
'js/bouncemarker.js','https://cdn.firebase.com/js/client/2.3.1/firebase.js','js/geofire.min.js','js/myScript.js'];