Menu

The request/response cycle

“Everything that happens between pressing Enter and seeing the page.”

View .md

You type https://example.com and press Enter. Here’s what happens, in order.

The steps between browser and server
1. DNS lookup · 2. connect · 3. TLS handshake · 4. request · 5. response

1. DNS: find the server’s address#

Computers connect to IP addresses, not names. The browser asks a DNS resolver: *“what’s the IP of example.com?"*The answer is cached for a while (the record’s TTL), so the next visit usually skips this step.

bash
dig +short example.com
text
93.184.215.14

2. Open a connection#

The browser opens a TCP connection to that IP on port 443 (because the scheme is https). HTTP/3 uses QUIC over UDP instead, but the role is the same: a reliable channel between the two machines.

3. TLS handshake#

For https, client and server use TLS to agree on encryption keys and the server proves it really is example.com with a certificate. After this, everything is encrypted.

Tip

curl -v shows this step too. Look for lines like SSL connection using TLSv1.3 and server certificate verification OK.

4. Send the request#

Now the actual HTTP request goes over the connection:

http
1GET / HTTP/1.1
2Host: example.com
3User-Agent: Mozilla/5.0 ...
4Accept: text/html

5. Get the response#

The server finds (or generates) the page and answers:

http
1HTTP/1.1 200 OK
2Content-Type: text/html; charset=utf-8
3
4<!doctype html>
5<html>...

6. …and then many more requests#

The HTML mentions CSS, JavaScript and images. For each of those the browser sends another request, usually reusing the same connection. A typical page makes dozens of them. Open your browser’s DevTools → Network tab and reload any page to see the list.

Measure it#

curl can time each phase:

bash
curl -o /dev/null -s -w "dns: %{time_namelookup}s\nconnect: %{time_connect}s\ntls: %{time_appconnect}s\nfirst byte: %{time_starttransfer}s\ntotal: %{time_total}s\n" https://example.com
text
dns: 0.012s
connect: 0.031s
tls: 0.068s
first byte: 0.101s
total: 0.102s

Notice how much time passes before the first byte of the response arrives. That’s why reusing connections matters.

Byte check

0/3

Answer these 3 questions to commit this byte to your learning path.

  1. What does the browser need first, before it can connect to example.com?
  2. What does the TLS handshake do?
  3. The HTML mentions 10 images. What does the browser do?
Search posts and bytes

Optional account

Keep your progress everywhere

Everything on AminBytes is free to read, with or without an account. Sign in only if you want your commits, streak and merged topics saved, on every device.

or

We keep only your name, avatar and which bytes you finished, and you can delete it all anytime. Privacy