HTML5 & Web APIs (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Script Loading Strategies: `async` vs `defer` vs `type="module"`.
senior LevelAsync & PromisesSystem Design
In Simple Words:
<script src="...">(Default): Blocks HTML parsing while downloading and executing immediately.<script async src="...">: Downloads in background without blocking HTML parsing. Executes immediately when downloaded, interrupting parsing and executing out of order. Best for independent analytics scripts.<script defer src="...">: Downloads in background without blocking. Executes only after HTML parsing completes, preserving original DOM document order beforeDOMContentLoaded. Best for application code.<script type="module" src="...">: Behaves likedeferby default, supports ES imports, and always executes in strict mode.