HTML & CSS · Senior · Question 49 of 75
How does defer differ from async on <script>?
- ✓Correct answer:
deferruns in order after HTML parsing,asyncruns as soon as it loads - 2
asyncblocks HTML parsing until it runs, whiledeferdoesn't - 3
deferworks only for inline scripts,asynconly for external ones
Explanation
A regular script stops the parser. defer downloads in parallel and executes in order before DOMContentLoaded - good for dependent application scripts. async executes as soon as it's downloaded - for independent scripts like analytics. Modules (type="module") behave like defer by default. Neither attribute affects inline scripts.