I have read that it is not recommended to instantiate jQuery multiple times in your HTML. This makes perfect sense to me, but:
In a simple scenario (tags are part of original HTML text), the browser definitely executes them one after another.
Detailed discussion with different caveats
BUT, the individual
<script> tags are executed sequentially.
For reference, please see
Please note that the above is only true of “straight up” execution of code in tags. The order can, however, be affected by:
Dynamic attachement of the
<script>tags – see the last section of this answer.
<script src="xxxx" /> would still be executed sequentially, BUT, it is quite possible that the browser would DOWNLOAD the code in parallel – depends on browser implementation (but still schedule the execution of downloaded code snippets in correct order).
Again, it would have no bearing on your browser JS engine’s execution order of those script pieces.
However, a far more important caveat is that if you actually attach the
<script> tags with external sources dynamically (e.g. via
appendChild() call), according to this SO post, as well as the MSDN blog the post was based on, non-IE browsers do NOT guarantee the order of execution! It will depend on which tag’s code finished downloading first!
The fewer calls you make that instantiate a jQuery object, the less overhead you have — but even if you are designing for old browsers running on 2nd generation hardware be wary of micro-optimizations. Profile your application and fix the parts that actually are the bottlenecks.
As for the way browsers handle multiple script tags — it varies from browser to browser, from version to version, and sometimes even from operating system to operating system. All browsers execute each script tag in document order:
However, other behaviors are not defined and there is variation. For example, Opera (at least on Windows XP for version 10.6) ran each script tag in its own context — so local variables in the 3rd script block would be out of scope if referred to in the 4th script block.
<script> var i = 42; </script> <script> alert(i); // Alerts "undefined" in Opera, but 42 in Firefox. </script>
As for having multiple script tags in HTML, there’s no reason why this would be a problem. As Nabab asked, I would be interested in seeing your source for that.