Skip to the workspace
Pebellslearn by building
How the Web Works  ›  Capstone Project

Browsers — the Other End of the Wire

Browsers and how they work? 15 minA browser turns one URL into a DNS lookup, a connection and many HTTP requests, then parses HTML and CSS into a page and runs JavaScript that may call your API.

backend / Browsers — the Other End of the Wire

Explore each scene at your own pace.

01 · The rule

The rule

Browsers — the Other End of the Wire

Most requests your backend answers come from a browser, and a browser is busier than it looks. One visit to the bookshop's page can make a dozen requests to your servers. When you know what the browser does with each answer, you know which responses slow the page down.

The rule

One URL becomes many requests, then a tree, then pixels.

When a shopper opens https://bookshop.example/books, the browser:

  1. Finds the server: a DNS lookup turns bookshop.example into an IP address (unless it is cached).
  2. Connects: it opens a TCP connection, and because of https, sets up encryption with TLS.
  3. Requests the document: it sends GET /books and receives HTML.
  4. Parses and discovers: while reading the HTML it builds the DOM, a tree of elements. Each <link rel="stylesheet">, <script src> and <img> it meets becomes another request.
  5. Styles, lays out, paints: it combines the DOM with the CSS rules, works out where every box goes, and draws pixels.
  6. Runs JavaScript: scripts can change the DOM and call your API, for example with fetch("/api/books").
<link rel="stylesheet" href="/static/site.css">
<script src="/static/app.js" defer></script>
<img src="/covers/42.jpg" alt="Cover of The Salt Road">

Those three lines mean three more requests after the HTML arrives.

Browsers also enforce a safety rule that backend developers meet early: the same-origin policy. A script from https://bookshop.example may not read a response from a different origin, such as https://api.bookshop.example, unless that server says it is allowed with CORS headers like Access-Control-Allow-Origin.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.