Hint
async executes as soon as downloaded (may block parsing); defer executes after HTML is parsed, in order
Both attributes tell the browser to download the script without blocking HTML parsing, but they differ in when the script executes.
Default (no attribute) — parsing blocks while the script is downloaded and executed. Render-blocking.
async — downloads in parallel; executes immediately when downloaded, even if HTML isn't done parsing yet. Order not guaranteed.
<script async src="analytics.js"></script>
{/* Good for: independent scripts like analytics — don't care about DOM or other scripts */}
defer — downloads in parallel; executes after HTML parsing is complete, in document order.
<script defer src="app.js"></script>
{/* Good for: scripts that need the DOM or must run in order (most app scripts) */}
| Blocks parsing | Execution time | Order preserved | |
|---|---|---|---|
| default | Yes | Immediately | Yes |
| async | No | When downloaded | No |
| defer | No | After parse | Yes |
defer to script tags. You mainly need to know this for third-party scripts added manually.