SUMMARY
JavaScript is inserted into HTML pages by using the <script>
element. This element can be used to embed JavaScript into an HTML page, leaving it inline with the rest of the markup, or to include JavaScript that exists in an external file. The following are key points:
- To include external JavaScript files, the
src
attribute must be set to the URL of the file to include, which may be a file on the same server as the containing page or one that exists on a completely different domain. - All
<script>
elements are interpreted in the order in which they occur on the page. The code contained within a<script>
element must be completely interpreted before code in the next<script>
element can begin so long asdefer
andasync
attributes are not used. - For nondeferred scripts, the browser must complete interpretation of the code inside a
<script>
element before it can continue rendering the rest of the page. For this reason,<script>
elements are usually...