<script defer> vs <script async>?
Options
- They are identical in how they load and run
deferwaits for parsing, in order;asyncdoes not (Correct option)asyncblocks HTML parsing until it has rundeferonly works on inline scripts in the page
Answer
defer runs after HTML parsing in document order; async runs as soon as it downloads, order not guaranteed
Why
A plain <script> stops the browser from reading the rest of the HTML until it downloads and runs.
Both attributes download in the background:
defer: runs after the HTML is fully parsed, in the order the scripts appear. Best for your app code.async: runs as soon as it arrives, in any order. Fine for independent scripts like analytics.
Remember
App scripts → defer. Independent third-party scripts → async.