Browser Internals6h estimated

The HTTP Request Lifecycle in Browsers

Difficulty
Importance

The problem

A page frequently needs to fetch additional data or resources after it has already loaded, without freezing the user interface while waiting — the browser needs a way to issue HTTP requests asynchronously and hand the eventual response back to JavaScript when it arrives.

Why now

HTTP fundamentals already defined the request/response protocol itself; this topic is where that protocol gets triggered from inside a running page, and it relies entirely on the event loop already covered to avoid blocking the page while the network round-trip is in flight.

Mental model

fetch() kicks off an HTTP request and immediately returns a Promise — the actual network round-trip happens off the main thread's timeline, and when the response arrives, its handling is queued through the exact same task-queue mechanism the event loop describes for any other async operation, not delivered instantly the moment bytes arrive.

Requires

Unlocks

Used in

Projects

  • Use fetch() to request data from an API, log the timing of each stage (request sent, response received, JSON parsed), and relate it back to the event loop
  • Deliberately trigger and diagnose a CORS error, then explain what the browser is protecting against

Examples

  • fetch('/api/user').then(r => r.json()) returns a Promise immediately; the actual data arrives later via the task queue
  • A CORS error occurs when a page at one origin tries to fetch from another origin that hasn't explicitly allowed it via response headers

Resources

Mastery checklist