Dynamic script addition should be ordered?

Posted by hawkettc on Stack Overflow See other posts from Stack Overflow or by hawkettc
Published on 2010-05-10T16:02:47Z Indexed on 2010/05/10 16:54 UTC
Read the original article Hit count: 247

Hi,

I'm adding some <script> tags dynamically to the head element after page load. I understand the scripts are loaded asynchronously, but can I expect them to be parsed in the order they are added?

I'm seeing the expected behaviour in Firefox, but not in Safari or Chrome. Looking at the document in Chrome developer tools and Firebug, both show the following -

<html>
  <head>
    ...
    <script type="text/javascript" src="A.js"></script>
    <script type="text/javascript" src="B.js"></script>
  </head>
  ...
</html>

However looking at the resource loading view, chrome seems to parse whichever is returned first from the server, while firebug always loads them in the order the script tags were added, even when B is returned first from the server.

Should I expect Chrome/Safari to parse the files in the specified order? Using Chrome 5.0.375.29 beta on OS X 10.6.3

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about dynamic-script-loading