Skip to content

Commit

Permalink
Update files/en-us/learn/javascript/first_steps/what_is_javascript/in…
Browse files Browse the repository at this point in the history
…dex.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
mb21 and github-actions[bot] authored Jul 20, 2024
1 parent 96d15c0 commit 3910a00
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ There are a few different strategies to make sure your JavaScript only runs afte

- In the external JavaScript example above, the script element is placed in the head of the document, before the HTML body is parsed. But because we're using `<script type="module">`, the code is treated as a [module](/en-US/docs/Web/JavaScript/Guide/Modules) and the browser waits for all HTML to be processed before executing JavaScript modules.

- Before browsers supported JavaScript modules, placing a script element in the head of the document could block the whole HTML of the page from displaying before the script was loaded. So we had to add `defer` and `async` attributes on the {{htmlelement("script")}} element, and then that could cause errors when the JavaScript was run but the HTML was not parsed yet. So we had to use the [DOMContentLoaded event](https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event). But unless you need to support very old browsers, don't do this, and simply use `<script type="module>` instead.
- Before browsers supported JavaScript modules, placing a script element in the head of the document could block the whole HTML of the page from displaying before the script was loaded. So we had to add `defer` and `async` attributes on the {{htmlelement("script")}} element, and then that could cause errors when the JavaScript was run but the HTML was not parsed yet. So we had to use the [DOMContentLoaded event](/en-US/docs/Web/API/Document/DOMContentLoaded_event). But unless you need to support very old browsers, don't do this, and simply use `<script type="module>` instead.

## Comments

Expand Down

0 comments on commit 3910a00

Please sign in to comment.