Interview Question

defer vs async on <script>?

Use defer for ordered page scripts; async suits independent scripts.

💡 Concept ✅ Quick Revision 🌐 HTML

Answer

Both `defer` and `async` download a script without stopping HTML download. • `async` runs as soon as ready, so order is not guaranteed. • `defer` waits for HTML parsing and keeps script order. • Choose the option whose defined semantics and behavior match the task.

💡 Simple Example

<script defer src="app.js"></script>

⚡ Quick Revision

Use defer for ordered page scripts; async suits independent scripts.