Head Elements
Script Tag
The <script> tag adds JavaScript to the page, either written inside it or loaded from a file.
<!-- external file (recommended) -->
<script src="app.js" defer></script>
<!-- inline -->
<script>
console.log("Page loaded!");
</script>| Attribute | Behaviour |
|---|---|
| (none) | Stops the page loading until the script has downloaded and run. |
defer | Downloads in the background and runs after the HTML is ready, in order. Best for most scripts. |
async | Downloads in the background and runs as soon as it arrives, in any order. Good for analytics. |
type="module" | Loads modern JavaScript modules. Deferred automatically. |