Scripts, Defer, and Document Order
<script src="/app.js" defer></script>
Why defer Helps
- The browser can keep parsing HTML.
- The script executes after the document is parsed.
- Timing becomes simpler for DOM-dependent code.
Common Pitfalls
- Large blocking scripts in the head
- Inline scripts that depend on elements not yet parsed
- Unclear ordering between multiple dependent scripts
What's Next
- Continue to 10. Entities, Symbols, and Encoding