HTML5 & Web APIs (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What are the differences between `defer`, `async`, and standard `<script>` loading?
junior LevelCode ExampleAsync & Promises
In Simple Words:
less
HTML Parsing: ====================[BLOCKED]=====================>
Standard Script: [Download][Execute]
HTML Parsing: ==================================================>
Async Script: [Download]
Execution: [Execute BLOCKS Parsing]
HTML Parsing: ==================================================> (HTML Finishes)
Defer Script: [Download] [Execute]
- Standard
<script src="...">: Pauses HTML parsing immediately while the script downloads and executes. Blocks rendering! <script async src="...">: Downloads in background without pausing HTML parsing. The moment downloading finishes, HTML parsing is paused to execute the script immediately. Execution order is non-deterministic (independent scripts like Google Analytics).<script defer src="...">: Downloads in background. Executes only after HTML parsing is completely finished, strictly in the order the scripts appear in the document. The best practice for application code.