Mission 03 / Browser foundations

Browser to DOM

Follow the browser from HTML source to the live document JavaScript can read and change.

Easy50 XPParsingDOMdefer

The flow

HTML becomes a live document

  1. The browser parses HTML and builds the DOM tree.
  2. It also processes CSS and calculates the styles and layout.
  3. JavaScript can find DOM elements and respond to events.
  4. The browser redraws affected parts when the DOM or styles change.
<script src="script.js" defer></script>

defer downloads the script while HTML is parsed and runs it after the document has been parsed, in document order.

Checkpoint

Why is defer useful here?