defer downloads scripts in parallel and runs them after HTML parsing in order. async downloads in parallel and runs immediately. Use defer for most scripts and async only for fully independent scripts like analytics.
Loading JavaScript
<!-- In head — blocks rendering (avoid) -->
<script src="app.js"></script>
<!-- Defer — runs after HTML parsed (recommended) -->
<script src="app.js" defer></script>
<!-- Async — runs as soon as downloaded -->
<script src="analytics.js" async></script>
<!-- Inline script -->
<script>console.log("hello");</script>
Use defer for most scripts. Use async for independent scripts like analytics.