I have this simple function which loads scripts into the current DOM:
function loadscripts ( async ) { if( async === undefined ) { async = false; } var scripts = []; var _scripts = ['jquery.min.js', 'bootstrap.min.js', 'plugins.js', 'main.js']; for(var s in _scripts) { scripts[s] = document.createElement('script'); scripts[s].type = 'text/javascript'; scripts[s].src = _scripts[s]; scripts[s].async = async; document.getElementsByTagName('head').appendChild( scripts[s] ); } } They are loaded fine and without no errors. I know there are event handlers when loading scripts programmatically:
- onreadystatechange, and
- onload, etc
Now I would like to wish to do the following:
- Load first script from the array, and when the event handlers are COMPLETE load the next one, and so on (recursively).
Sorry, I have not provided the onreadystatechange and onload events in my function.