The order of javascript does indeed matter. Javascript is executed in a linear manner within the page, so if you have two <script>
tags like this:
<script src="test1.js"></script>
<script src="test2.js"></script>
test1.js
will be loaded and run first, then test2.js
. Anything declared globally in test1.js
will be accessible in the second script, but not the other way around.
A side effect of this is that scripts also block when they are loaded, so if test1.js
took a long time to load, you would see that slow down the page loading time. This is why it is recommended to put any javascript that's not immediately necessary at the bottom of your page, so that almost the entire thing will show up right before the javascript loading slows it down.
Inside the "on ready" event in jquery, you should theoretically have access to anything that was loaded as part of the DOM, as this should technically not fire before the DOM structure has been entirely built.