Is it true that first line of Javascript will be executed only after all script tags with src attribute are downloaded and evaluated?
By first 开发者_运维问答line of Javascript I meant the JS code inside tags with no "src" attribute.
By right it will be evaluated top down.
Read more about it from my previous answer: Load and execution sequence of a web page?
Let me explain here:
<script type="text/javascript">
alert(jQuery); // alerts jQuery's namespace
</script>
<script type="text/javascript" src="jquery.js"></script>
The result is alerting undefined
.
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
alert(jQuery); // alerts jQuery's namespace
</script>
The result is alerting a object/function where defined.
The scripts are executed in the order they are listed in the html. It does not matter if they are inline JavaScript (within <script>
tags) or if loaded as external scripts (<script src="xx.js">
).
精彩评论