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:
- Finds the server: a DNS lookup turns
bookshop.exampleinto an IP address (unless it is cached). - Connects: it opens a TCP connection, and because of
https, sets up encryption with TLS. - Requests the document: it sends
GET /booksand receives HTML. - 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. - Styles, lays out, paints: it combines the DOM with the CSS rules, works out where every box goes, and draws pixels.
- 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.