JavaScript: How can I delay running some JS code until ALL of my asynchronous JS files downloaded?

Posted by Henryh on Stack Overflow See other posts from Stack Overflow or by Henryh
Published on 2010-05-10T04:33:01Z Indexed on 2010/05/10 4:58 UTC
Read the original article Hit count: 275

UPDATE:

I have the following code:

<script type="text/javascript">
function addScript(url) {
    var script = document.createElement('script');
    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
}   
addScript('http://example.com/One.js');
addScript('http://example.com/Two.js');
addScript('http://example.com/Three.js');
addScript('http://example.com/Four.js');

...

// run code below this point once both Two.js & Three.js has been downloaded and excuted

</script>

How can I prevent code from executing until all required JS have been downloaded and executed? In my example above, those required files being Two.js and Three.js.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about web-development