Computing Foundations › How the Internet Works › Day 15

Day 15: What Happens When You Load a Web Page

Day 15 of 365 — What Happens When You Load a Web Page

After this lesson you will be able to trace, stop by stop, the journey a web request takes — URL, DNS, TCP, TLS, HTTP, server, response, render — and use that map to reason about latency, failures, and the layered structure of the internet.

Course
Computing Foundations
Category
How the Internet Works
Reading time
≈ 40 min
Practical time
≈ 30 min
Lesson duration
1h 10m
Last verified
2026-07-12

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-015-what-happens-when-you-load-a

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
    cd labs/sections/computing-foundations/day-015-what-happens-when-you-load-a
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters


The idea in plain language

Diagram: network latency compared with bandwidth


Historical background

Diagram: how each HTTP version reduced round trips


What it is — and what it is not

It is:

It is not:


Why it was created and what problems it solves

Diagram: the round trips spent before a page's first byte arrives


How it works

The journey, stop by stop

Diagram: the journey of a web request from browser to server and back

#StopWhat happensCost
1URL parsingSplit into scheme, host and path; https defaults to port 443free
2DNS lookupTurn the name into an address0–1 round trips
3TCP connectionThree-way handshake; guarantees order and completeness1 round trip
4TLS handshakeServer proves it owns the name; keys agreed1–2 round trips
5HTTP requestMethod, path and headers — a short block of text—
6The serverReads a file, runs code, queries a databasethe variable part
7HTTP responseStatus line, headers, and usually HTML—
8Parse and fetch moreThe HTML names CSS, scripts, images, fontsoften parallel
9RenderBuild the model, style, script, lay out, paint—

The layered model underneath

Diagram: how each network layer wraps the data from the layer above

Diagram: the four layers of the internet protocol stack

LayerJobExampleUnit
ApplicationAgree what is asked and returnedHTTP, DNS, TLSMessage
TransportDeliver bytes reliably to the right programTCP, UDPSegment
InternetAddress and route across networksIPPacket
LinkMove bits to the next physical deviceWi-Fi, EthernetFrame

Why round trips matter

Diagram: connection setup cost compared with the server's actual work


An everyday analogy

Diagram: serving from one origin compared with serving from edge locations

Ordering a book from another country.

The orderThe request
Looking up the shop’s addressDNS
Phoning to check they are openTCP handshake
Agreeing you are talking to the real shopTLS handshake
Saying which book you wantThe HTTP request
Them finding it on a shelfThe server’s work
The parcel arrivingThe response
Realising you also need the sequelSub-resource requests

Examples in practice


Implications: security, privacy, performance, scalability, and cost

Diagram: the characteristic failure at each stage of a web request


Alternatives: free, open source, and commercial

Diagram: how curl's timing fields map to the stages of a request

ToolTypeWhat it shows you
Browser developer toolsBundled, freeThe whole waterfall, per resource
curl -wFree, built inTime spent in each phase, numerically
digFree, built inExactly what DNS returned, and from where
ping, tracerouteFree, built inRound-trip time and the path taken
mtrFree, open sourceTraceroute and ping combined, continuously
WebPageTestFree tierThe same page loaded from other continents

TermWhat it actually is
Round-trip timeTime for a signal to reach the server and return
LatencyDelay before transfer begins
BandwidthHow much data can flow per second
ThroughputHow much actually flowed
HandshakeThe exchange that establishes a connection
CDNCopies of content held physically closer to users

When to use it — and when not to


The AI connection

Diagram: a first page load compared with a repeat visit


Knowledge check

quiz:
  question: "An API responds in 40 ms when called from a server in the same region and 350 ms from a laptop overseas, with identical payloads. Upgrading the laptop's internet plan changes nothing. Why?"
  options:
    - "The extra time is round-trip latency set by distance, which bandwidth does not affect"
    - "The overseas request is being throttled by the API provider's rate limits"
    - "The laptop's connection has insufficient bandwidth for the response size"
    - "TLS negotiation is slower on consumer hardware than on server hardware"
  answer_index: 0
  explanation: "The payload is identical, so capacity is not the constraint. The difference is the time a signal takes to cross the distance and come back, several times over for setup — a floor set by physics that no plan upgrade moves."

Hands-on exercise

Time each stage of a real request and find where the time goes. Worked through fully in the Day 15 lab directory.

What you are measuringCommand
Round-trip time to a hostping -c 5 example.com
What DNS returnsdig example.com +short
Time spent in each phasecurl -w "@curl-format.txt" -o /dev/null -s https://example.com
The path packets taketraceroute example.com
A cold connection versus a warm oneRun the curl twice and compare
The same site from far awayA public testing service, or a remote host

Expected output

namelookup:  0.024s
connect:     0.061s
appconnect:  0.128s
starttransfer: 0.171s
total:       0.174s

Validate your work

Troubleshooting

Common mistakes


Practice assignment


Extension challenge


Quiz

Q1. You type https://example.com and press Enter. Which step happens FIRST, before the browser can request the page?

  1. The server renders the HTML for you
  2. The browser paints pixels to the screen
  3. The TLS handshake encrypts the page content
  4. The browser parses the URL and looks up the IP
Show answer

Answer: D. The browser parses the URL and looks up the IP

The browser first splits the URL into scheme, host, and path, then performs a DNS lookup to translate the host name into an IP address the network can route to. Only after there is an address can a connection be opened and the page requested.

Q2. What does the Domain Name System (DNS) actually do?

  1. It translates a name like example.com into an IP address
  2. It guarantees that packets arrive in order and complete
  3. It encrypts the connection so eavesdroppers cannot read it
  4. It renders the HTML into a visible page
Show answer

Answer: A. It translates a name like example.com into an IP address

DNS is the internet's directory: it maps memorable names to the numeric IP addresses the network routes to. Reliability is TCP's job, encryption is TLS's job, and rendering is the browser's job.

Q3. On a fresh https connection, which sequence of setup steps happens in order before the first HTTP request is sent?

  1. TLS handshake, then TCP connection, then DNS lookup
  2. DNS lookup, then TCP connection, then TLS handshake
  3. DNS lookup, then TLS handshake, then TCP connection
  4. TCP connection, then DNS lookup, then TLS handshake
Show answer

Answer: B. DNS lookup, then TCP connection, then TLS handshake

You need an address before you can connect, so DNS comes first; then TCP opens the connection to that address; then TLS negotiates encryption over that connection. Only after all three can the HTTP request go out.

Q4. Why does distance to a server matter so much for how fast a page starts to load?

  1. Longer distance reduces the available bandwidth to zero
  2. DNS cannot resolve names for far-away servers
  3. Each round trip takes longer, and setup needs several
  4. Servers far away always have slower processors
Show answer

Answer: C. Each round trip takes longer, and setup needs several

Signals travel at a finite speed, so a longer distance means a longer round-trip time. Because setting up a connection (TCP handshake, TLS handshake, DNS misses, the request itself) costs several round trips, distance multiplies the setup delay — this is latency, and a faster computer cannot remove it.

Q5. In the internet's layered model, what is the job of the transport layer (TCP)?

  1. To move bits over the physical Wi-Fi or Ethernet medium
  2. To address and route individual packets across networks
  3. To agree what is being asked for and returned
  4. To deliver an ordered, reliable byte stream to the right program
Show answer

Answer: D. To deliver an ordered, reliable byte stream to the right program

TCP (the transport layer) turns the unreliable packet delivery of IP into an ordered, complete byte stream for a specific program, retransmitting anything lost. Routing is IP's job (internet layer), moving bits is the link layer's job, and agreeing on the message format is the application layer's job.

Q6. A curl run prints: dns=0.030s connect=0.050s tls=0.100s total=0.180s. How long did the TLS handshake take?

  1. About 50 milliseconds
  2. About 100 milliseconds
  3. About 30 milliseconds
  4. About 180 milliseconds
Show answer

Answer: A. About 50 milliseconds

Each number is the elapsed time from the start at which that stage finished. TCP connect finished at 0.050s and TLS finished at 0.100s, so the TLS handshake took the gap between them: about 0.050s, or 50 milliseconds.

Q7. Your ping to a website times out with no replies, but the site loads fine in your browser. What is the most likely explanation?

  1. The site is down and the browser is showing a cached copy
  2. The server or network blocks ping (ICMP), which is separate
  3. DNS is broken, so the browser guessed the address
  4. The TLS certificate has expired
Show answer

Answer: B. The server or network blocks ping (ICMP), which is separate

Ping uses the ICMP protocol, which many servers and networks block on purpose. Web pages travel over TCP on port 443, a different path, so a blocked ping does not mean the site is down — always confirm reachability with a tool like curl.

Q8. The first response to a page load is usually just an HTML document. What does the browser do next?

  1. Nothing more — the single response contains the entire page
  2. It closes the connection and reports the page as finished
  3. It reads the HTML and requests the CSS, scripts, images, and fonts
  4. It re-runs the DNS lookup for every image individually
Show answer

Answer: C. It reads the HTML and requests the CSS, scripts, images, and fonts

The initial HTML is a skeleton that references more resources. The browser parses it, issues additional HTTP requests for the stylesheets, scripts, images, and fonts it names — usually reusing the open connection — and renders the page as those pieces arrive.

Glossary

URL
A Uniform Resource Locator — the full address of a resource on the web, made of a scheme (such as https), a host name, and a path, plus any query.
DNS
The Domain Name System, the internet's directory service that translates a human-friendly name like example.com into a numeric IP address.
IP address
The numeric address (such as 104.20.23.154) that identifies a machine on the network, so packets can be routed to it.
TCP
The Transmission Control Protocol, which delivers a reliable, ordered stream of bytes between two programs, retransmitting anything lost.
TLS
Transport Layer Security, the protocol that encrypts a connection and verifies the server's identity so traffic is private and tamper-proof; the S in https.
HTTP
The HyperText Transfer Protocol, the request-and-response format a browser and server use to ask for and return web resources.
round-trip time
The time for a signal to travel to the server and back again, abbreviated RTT; the basic unit of network delay.
latency
The delay before data begins to arrive, dominated by round-trip time and set largely by distance; distinct from bandwidth.
bandwidth
The amount of data a connection can carry per second; important for large transfers but not for the round trips of connection setup.
packet
A small, individually addressed chunk of data that the network routes independently; messages are split into packets and reassembled at the destination.
protocol
An agreed set of rules two computers follow to communicate, such as HTTP, TCP, IP, or TLS.
client
The program that initiates a request and waits for a reply, such as your web browser.
server
The program that listens for requests and returns responses, such as the machine hosting a website.
encapsulation
The layered wrapping of data as it goes down the network stack — an HTTP message inside a TCP segment inside an IP packet inside a link frame — unwrapped again at the other end.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.