defer attribute
A script attribute that downloads the script in the background and runs it, in document order, only after the HTML has finished parsing.
In more detail
defer keeps the parser moving and preserves order between scripts, which suits code that needs the full DOM. Module scripts behave like defer by default.
Related terms
- async attribute — A script attribute that downloads the script in the background and runs it as soon as it arrives, without waiting for parsing to finish or for other scripts.
- script element — The HTML element that loads or contains JavaScript for the page.
- ES module — A JavaScript file that uses import and export to share code with other files, loaded in the browser with <script type="module">.
- critical rendering path — The sequence of steps from receiving HTML, CSS and JavaScript to drawing the first pixels: build the DOM and CSSOM, the render tree, layout and paint.
Taught in
- Critical Rendering Path: Preload, Prefetch And Scripts — Frontend Architecture & Web Platform