You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
```smart header="The `async` attribute is only for external scripts"
137
+
Just like `defer`, the `async` attribute is ignored if the `<script>` tag has no `src`.
138
+
```
139
+
136
140
## Dynamic scripts
137
-
141
+
138
142
There's one more important way of adding a script to the page.
139
143
140
144
We can create a script and append it to the document dynamically using JavaScript:
@@ -188,7 +192,7 @@ But there are also essential differences between them:
188
192
|`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. |
189
193
|`defer`|*Document order* (as they go in the document). | Execute after the document is loaded and parsed (they wait if needed), right before `DOMContentLoaded`. |
190
194
191
-
In practice, `defer` is used for scripts that need the whole DOM and/or their relative execution order is important.
195
+
In practice, `defer` is used for scripts that need the whole DOM and/or their relative execution order is important.
192
196
193
197
And `async` is used for independent scripts, like counters or ads. And their relative execution order does not matter.
0 commit comments