I'm trying to load my js files asynchronously, with the code:
function load_js() {
var scripts = [
'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
'http://code.jquery.com/ui/1.10.2/jquery-ui.min.js',
'/js/libs/joose.min.js',
'/js/observer.js',
'/js/resume-library.js'
];
for( var i = 0; i < scripts.length; i++){
var element = document.createElement("script");
element.src = scripts[i];
document.body.appendChild(element);
}
}
if (window.addEventListener)
window.addEventListener("load", load_js, false);
else if (window.attachEvent)
window.attachEvent("onload", load_js);
else window.onload = load_js;
but, the order doesnt always follow the order of the array, sometimes a file may take longer to load etc.
how can i guarantee that the files will load in the order of the array?