<script>
Used to included the javascript code in HTML.
Basic format:
<script src= "scripts/digital_clock.js"></script>
module
If you have used modules in your code, i.e. import, export directives, made the script type as module.
<script type="module"></script>
- defer: All of the modules the script imports will be loaded after the template HTML is rendered
- can be overriden by async attribute
default loading method
- document.write() -- synchronous, execute the script in the middle of template redendering
async & defer
- <script defer src="deferred.js"></script>
- defer the script execution till after template rendered
- All scripts still run in order
- <script async src="async.js"></script>
- executes the script immediately, not blocking the rendering
- Order not guranteed
on demand loading
- Create a script tag from javascript
DOM
Represent the HTML document, mirror the tree structure
- There is a JavaScript class corresponding to each HTML tag type
- <body> = HTMLBodyElement
- <table> = HTMLTableElement
- DOM API includes methods for
- creating new Element and Text nodes
- inserting them into the document as children of other Element objects
- moving elements within the document
- removing elements entirely