commit
6f24128e44
1 changed files with 2 additions and 2 deletions
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
In modern websites, scripts are often "heavier" than HTML: their download size is larger, and processing time is also longer.
|
In modern websites, scripts are often "heavier" than HTML: their download size is larger, and processing time is also longer.
|
||||||
|
|
||||||
When the browser loads HTML and comes across a `<script>...</script>` tag, it can't continue building the DOM. It must execute the script right now. The same happens for external scripts `<script src="..."></script>`: the browser must wait until the script downloads, execute it, and only after process the rest of the page.
|
When the browser loads HTML and comes across a `<script>...</script>` tag, it can't continue building the DOM. It must execute the script right now. The same happens for external scripts `<script src="..."></script>`: the browser must wait for the script to download, execute the downloaded script, and only then can it process the rest of the page.
|
||||||
|
|
||||||
That leads to two important issues:
|
That leads to two important issues:
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ But there are also essential differences between them:
|
||||||
|
|
||||||
| | Order | `DOMContentLoaded` |
|
| | Order | `DOMContentLoaded` |
|
||||||
|---------|---------|---------|
|
|---------|---------|---------|
|
||||||
| `async` | *Load-first order*. Their document order doesn't matter -- which loads first | Irrelevant. May load and execute while the document has not yet been fully downloaded. That happens if scripts are small or cached, and the document is long enough. |
|
| `async` | *Load-first order*. Their document order doesn't matter -- which loads first runs first | Irrelevant. May load and execute while the document has not yet been fully downloaded. That happens if scripts are small or cached, and the document is long enough. |
|
||||||
| `defer` | *Document order* (as they go in the document). | Execute after the document is loaded and parsed (they wait if needed), right before `DOMContentLoaded`. |
|
| `defer` | *Document order* (as they go in the document). | Execute after the document is loaded and parsed (they wait if needed), right before `DOMContentLoaded`. |
|
||||||
|
|
||||||
In practice, `defer` is used for scripts that need the whole DOM and/or their relative execution order is important.
|
In practice, `defer` is used for scripts that need the whole DOM and/or their relative execution order is important.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue