How does the use of async
and defer
differ when considering the script execution after download and its impact on page performance?
Async
- Blocks the parsing of the page when executed
- Executed as soon as it is available
Defer
- Executes after the page has finished parsing
- Executes before the
DOMContentLoaded
event - Respects scripts order
To me it seems that defer
would have a lower impact, since the execution after download happens after page parsing, while async
script execution after download blocks the parsing. But why then I see so often the use of async
and defer
together, where the later is just a fallback? Async seems just to be the modern way to go but I do not get why. If both async
and defer
work for my case, wouldn’t defer
have lower performance impact? Or is the fact of executing scripts asynchronously a win over deferring, even if the async
blocks parsing?