You tap a link and a page appears. It feels like one thing. It is not. One tap starts dozens of requests, each one a small trip of its own. This lesson counts them. It shows what a single request is, why one page load needs many, and where the journey goes next: Lesson 01, the full trip from click to answer.
Difficulty: Beginner · Know this first: F26 — The Browser and the Page
Every request charges a little time. The bar below counts the work in this lesson's scenarios, not milliseconds on a live system: the numbers are the requests and their teaching-example costs. The shape is honest: the first visit asks for everything, the second visit asks for almost nothing, and a failed picture costs little because it does not block. Step through the lesson or switch the scenario and watch the bar change.
Extra diagram · from scratch to master
Start with one click. Add one request at a time until the whole page load is counted, failed picture included.
Extra diagram · from scratch to master
Start with this lesson. Add one hop at a time until the full trip from Lesson 01 is on the map.
Pick a kind of page and the simulator counts its requests by type: document, stylesheet, scripts, images, fonts, and API calls. The counts are a fixed teaching table for each page type, so every total is exact. The lesson is the shape: simple pages ask little, rich pages ask a lot.
Five kinds of pages, from a bare blog post to a dashboard that never stops asking. Each one has a fixed count in this simulator.
On a second visit the browser already has the stylesheet, the scripts, and the pictures. It only rechecks the document and the live data.
Try this: (1) Simple blog post, first visit. 1 document + 1 stylesheet + 2 scripts + 3 images + 1 font = 8 requests, no API calls. (2) Shop product page, first visit. 1 + 1 + 5 scripts + 12 images + 1 font + 3 API calls = 23 requests. (3) Same shop page, second visit. The stylesheet, scripts, images, and font come from the cache: 1 document + 3 API calls = 4 requests. (4) Web app dashboard, first visit. 1 + 1 + 8 scripts + 2 images + 1 font + 6 API calls = 19 requests, and the API calls keep coming after the page loads.
Three questions. No score is saved anywhere — this is just you against the material.
I take the same idea four times here. First I learn what it is and why it exists. Then I learn to use it and read what it tells me. Then I design with it so one failure cannot take the system down. Last I run it for the world.
Definition: One tap starts many requests. The first fetches the HTML document. The document lists everything else the page needs: the stylesheet, the scripts, the pictures, the fonts. Each item on the list is its own request, its own trip. A simple page is about a dozen requests. A rich page can be a hundred.
Types:
Uses: I use this when a page feels slow. I count the requests before I blame the server, because the count is often the answer.
Dimensions: At low counts a page loads fast and the requests are invisible. What breaks first is a page that grew one picture at a time, and I notice it in the request count, not in the server logs. It costs nothing to learn to count. It costs hours to debug a page without counting. The trade is simple: every ingredient buys something the page needs, and every ingredient costs a request.
Definition: The first visit fetches everything. The second visit reuses the cache: the stylesheet, the scripts, the images, and the fonts are already on the machine, and only the document and the live data cross the network. The cache is why the second visit feels fast, and why a changed page can look old until the cache expires.
Types:
Uses: I use the browser's network view at this level. I count the requests on a first visit and a second visit, and I compare them before I say whether a page is fast.
Dimensions: As a page grows, the first-visit count grows with it, and the cache is the only thing that keeps repeat visits fast. What breaks is a piece that never caches, and I notice it when the second visit is as slow as the first. It costs cache headers set on purpose for every piece. The trade is that a cached piece is fast and can be stale, so the expiry is chosen per piece, not per page.
Definition: At this level I design the count: fewer requests, smaller pieces, scripts that load late, images that load when they are needed, and data that arrives after the page is usable. I measure the moments: first text, first paint, and the moment the page answers. The budget is a number of requests and a number of kilobytes, and the page must fit inside both.
Types:
Uses: I use this when a page is slow and the server is fine. I cut the count, not the server, because the count is where the time goes.
Dimensions: At ten times the traffic the server is still fine and the page is still heavy, because the weight is per user. What breaks is the page that grew without a budget, and I notice it in the load time on a slow connection. It costs a budget per page and the habit of measuring on a slow network, not just on fast office Wi-Fi. The trade is that every feature buys weight, and the budget is the only thing that keeps the weight honest.
Time each step. A request has stages, and each stage takes time. I time them separately with curl -w. DNS lookup, connection, first byte, and total. The slowest stage is the one to fix, and the breakdown tells me which one it is.
$ curl -s -o /dev/null -w "dns:%{time_namelookup} connect:%{time_connect} start:%{time_starttransfer} total:%{time_total}\n" https://example.com
dns:0.001047 connect:0.001298 start:0.303816 total:0.344642
Every flag in the commands above, letter by letter.
curl -w takes a format string, and each %{...} is one timing. %{time_namelookup} is DNS time. %{time_connect} is TCP time. %{time_starttransfer} is time to first byte. %{time_total} is the whole request.%{...} parts are replaced. That is why the output reads dns:0.001047 instead of a bare number.%{time_appconnect} is the TLS handshake time. On plain http it is 0. On https it is the gap between connect and first byte. When a secure request is slow, this number says whether the handshake or the server was slow.Check it: run the command above, then add appconnect:%{time_appconnect} to the -w string and run it again. On https, appconnect is a real number, like 0.088. On http, it is 0.
Try it: run the command above. DNS took a millisecond. The connection took a millisecond. The wait for the first byte took three tenths of a second. The server is the slow part here, not the network. Fix the server, not the DNS.
The proxy in the middle. A machine can send its traffic through a proxy, and the proxy changes every step of the journey. I list the proxy settings by name, never by value, because the values can hold passwords. The names alone tell me a proxy is in play.
$ env | grep -iE '^(https?|all|no)_proxy' | cut -d= -f1 | sort -u
ALL_PROXY
HTTPS_PROXY
HTTP_PROXY
NO_PROXY
all_proxy
http_proxy
https_proxy
no_proxy
Every flag in the commands above, letter by letter.
env takes no flags here. It prints every environment variable, one per line, in the form NAME=value.grep -iE combines two flags. -i ignores case, so PROXY matches proxy. -E turns on extended regex, so the pattern can use ^, |, and ?. The pattern keeps only the proxy variables.cut -d= -f1: -d= splits each line on =. -f1 keeps field 1, the name. Without cut, the values print too, and proxy values hold secrets.sort -u: -u means unique. It sorts the names and drops duplicates. Without -u, a name set twice prints twice.cut -d= -f2 keeps field 2, the value. The values can hold passwords, so print them only for yourself and never paste them anywhere.Check it: run the command above. It prints only the names: ALL_PROXY, HTTPS_PROXY, HTTP_PROXY, NO_PROXY, and the lowercase twins. Then run it with -f2 instead of -f1 and watch the values appear. Do not paste them anywhere.
Try it: run the command above. It prints only the names, not the values. If the list is empty, there is no proxy. If it is not empty, your requests go through a proxy, and a failure may be the proxy, not the server. Never print the values. They can hold credentials.
Definition: At this level one request is the unit of the whole course. Every request is a trip through DNS, TLS, the balancer, the gateway, the app, and the data. The count is the load on the system, and the trip is the cost of each request. I design pages that ask little, systems that answer fast, and trips that survive a failure in any hop. Module 0 ends here. The core begins with the trip itself.
Types:
Uses: I use this when I hand a new engineer the course: start at the click, count the requests, walk one of them all the way, and the system stops being a mystery.
Dimensions: At a hundred times the users the count is the capacity plan: so many requests per page, so many pages per user, so many users per second. What breaks is the page that asks the most, and I notice it in the request rate before I notice it in the latency. It costs a budget that covers the count and the trip together. The trade is that a page that asks little costs little to serve, and a page that asks much must earn every request.
The request that never leaves. A request can fail before a single byte leaves the machine. The name does not resolve, the connection is refused, or the proxy is down. I test the stages in order, and the first one that fails is the answer. The request never travelled, so the server cannot be the cause.
$ curl -s -o /dev/null -w "%{http_code}\n" --max-time 3 http://127.0.0.1:9/
000
$ getent hosts example.com
198.18.48.185 example.com
Every flag in the commands above, letter by letter.
curl -s -o /dev/null -w "%{http_code}\n" --max-time 3: -s hides progress. -o /dev/null throws the body away. -w prints the status code. --max-time 3 gives up after 3 seconds. On port 9 nothing listens, so the answer is 000.getent hosts looks a name up the way the system does, files first, then DNS. It prints the address and the name.Check it: run both commands above. The first prints 000, because nothing listens on port 9. The second prints 198.18.48.185 for example.com. One command fails fast. The other answers.
Try it: run both commands. The first fails with 000, because nothing listens on port 9. The second succeeds, because the name resolves. The request to port 9 never left the machine in any meaningful sense. It was refused at the door. That is a different fault from a request that left and got no answer.
The load event is the browser's announcement that the document and its named pieces are in place. It is not the moment the page is usable. Scripts can run after it, API calls can arrive after it, and pictures can fill in after it. A page can fire its load event and still show a spinner. Loaded and ready are two different moments.
Lazy loading is the habit of asking later. An image below the fold is not fetched until the user scrolls near it. A script for comments is not fetched until the page is usable. The page asks for what it needs now, and the rest waits. The count is the same in the end. The timing is what changes.
HTTP/2 and HTTP/3 changed the counting. Many requests share one connection now, so the cost of each extra request is smaller than it used to be. The count still matters, because each request is still work for the server, but the network cost per request fell. A page with a hundred small requests is less punishing than it was ten years ago, and still more punishing than a page with ten.
Third-party requests are the ones you did not write. Analytics, ads, fonts, videos: each one is a request to a server you do not control, and each one can be slow or down without your server knowing. A page that waits for a third party waits for a stranger. The rule is simple: never let a stranger block your page.
At 10x the traffic, the shape holds. More users, same count per page, and the total requests grow with the users. I watch the request rate per page, because it is the load the system must carry.
At 100x, the design changes. The pages are served from the edge, the pieces are cached there, and the API calls go to the nearest region. The count per page is the same. The distance per request is shorter.
# count the requests a page makes (teaching example)
# open the browser's developer tools, Network tab, reload the page
# each row is one request: the document, the stylesheet,
# the scripts, the images, the fonts, the API calls
#
# a simple page shows about 9 rows
# a shop page shows about 23 rows
# a news page shows about 34 rows
What the snippet means: the browser's Network tab lists every request a page makes, in order, with its size and its time. There is no command to run. You open the tools, reload, and count the rows. The rows are the true size of the page load, and they are the first thing I look at when a page feels slow.
Try it: the timing breakdown. Run the curl timing command from the Advanced section and read the four numbers. DNS, connect, first byte, total. Name the slowest stage out loud. That stage is where your next investigation starts. A fast DNS and a slow first byte means the server. A slow DNS means the resolver. The numbers decide, not the feeling.
$ curl -s -o /dev/null -w "dns:%{time_namelookup} connect:%{time_connect} start:%{time_starttransfer} total:%{time_total}\n" https://example.com
dns:0.001047 connect:0.001298 start:0.303816 total:0.344642
A shop's product page got slow over a month, a little at a time. No deploy was blamed, because no single deploy made it slow. The page just got heavier, one picture at a time, until users on mobile connections started leaving before it loaded. The server was fine. The page was the problem, and the page had grown quietly.
Three things. First, a budget per page, written down: so many requests, so many kilobytes, and any change that breaks it needs a reason. Second, a check that counts the requests on every change, so the growth is visible the week it happens, not a month later. Third, the gallery images are lazy now: they load when the user scrolls to them, not before. The page loads fast again, and the pictures are still there when the user wants them. The lesson was not about images. It was about quiet growth: a page that gains one request a week is a slow page in a month, and nobody notices until the users leave.
Design a product page for a shop that must load its first picture in under one second on a slow mobile connection. The page has a product picture, a price, a description, reviews, related products, and a chat widget.
Start with the count. The first screen needs the document, the stylesheet, one picture, and the price: four requests. The description is text in the document. The other 11 pictures load when the user scrolls to them, not before. The reviews call happens after the first paint, and the related products after that. The chat widget loads last, after the page is usable, and never blocks anything. The budget is one second for the first picture: about 300 ms for the document, 200 ms for the stylesheet, and 500 ms for one picture sized for a phone.
Loading one picture first buys a fast first screen and costs the gallery arriving later, which is fine, because the user looks at the first picture first. Deferring the reviews buys speed and costs reviews that arrive a second later. Deferring the chat widget buys a page that never waits for a stranger and costs a chat button that appears late. And the budget is for the first screen, not the whole page: the rest can arrive after, because a shopper buys from the first screen.