You type an address, you press enter, and a page appears. Behind that simple moment there is a fixed sequence of steps, and every one of those steps is a piece of machinery that you can look at and learn.
This is the first lesson in the How the Web Works module, and the next lesson in this module is about "What Are the Parts of a Complete HTML Page?".
What is the full journey?
The journey has five stages. You turn the name into an address, you open a connection to that address, you ask for one document, the server sends it back, and the browser builds the page from it.
1. RESOLVE example.com -> 93.184.216.34 (DNS lookup)
2. CONNECT open a connection to that address (TCP, then TLS for https)
3. REQUEST "GET /index.html HTTP/1.1" + headers
4. RESPONSE "HTTP/1.1 200 OK" + headers + body (the HTML)
5. RENDER parse the HTML, fetch the CSS, JS and images, paintStep one is the phone book. The DNS turns a name like example.com into an IP address such as 93.184.216.34.
Step two is the dialling. The browser opens a connection to that address, and on a secure site it wraps the connection in encryption before anything else is sent.
Step three is asking for one specific document. The browser sends a request that names the file it wants.
Step four is what comes back. The server replies with a status line, a set of headers, and the body of the page.
Step five is the part that people call "loading the page", but it is really five more requests, because the HTML points at the CSS, the JavaScript, and the images.
What does a request actually look like?
Underneath every page there is plain text that travels over the connection. That text is the request, and you can read it yourself in the developer tools of any browser.
The browser writes a request line, some headers that describe what it wants and who it is, and an empty body for an ordinary page visit.
GET /tutorials/python HTTP/1.1
Host: tutorsbot.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
Accept: text/html,application/xhtml+xml
Accept-Encoding: gzip, br
Connection: keep-aliveThe response mirrors the request. There is a status line, there are headers that describe the body, and then there is the body itself.
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Cache-Control: public, max-age=600Why does the address scheme matter?
The http:// and the https:// are the same protocol with one difference. The secure version wraps every byte in encryption.
The server shows a certificate that proves it is who it claims to be, and the browser refuses the page if the certificate does not check out.
http://example.com plain text on the wire, visible to any network in between
https://example.com encrypted, and the server proves its identity firstEverything else in an address works in the same way in both of them. The path, the query string, and the fragment are all unchanged.
A path names a resource on the server. A query string carries extra parameters. A fragment after the # is handled by the browser alone, and it is never sent to the server.
What does the browser do with the response?
The body of the response is the HTML, and the browser parses it into a tree of elements.
While it parses, the browser finds the stylesheet and the scripts, asks for them, and applies the CSS to the elements as it goes.
This is why a stylesheet in the document head blocks the rendering. The browser refuses to paint a page until it knows how that page should look.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>A page the browser can render immediately</title>
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<h1>Hello</h1>
<p>This markup arrived in the first response, so it paints early.</p>
</body>
</html>The order in which the resources arrive changes what the reader sees.
A page that arrives quickly but whose stylesheet is slow shows unstyled text for a moment. A page whose HTML arrives slowly shows nothing at all until the markup itself is there.
That is the practical reason that the critical CSS in the head matters, and it is the reason why the images are marked with their size, so that the page does not jump while they load.
What can you check yourself?
Every browser can show you the raw conversation. You open the developer tools, you switch to the network tab, and you reload the page. You see every request, its status, its size, and its timing.
Reading that list is the fastest way to understand why a page feels slow.
What is the difference between a GET and a POST request?
Both of them are ways of asking a server for something. They differ in where the extra information goes, and in what happens when you send the request twice.
A GET request puts its parameters in the query string, which is the part after the ? in the address. That makes the whole request visible in the address bar, and it makes the page easy to share.
A POST request puts its parameters in the body of the request. The body is not part of the address, and it is not shown in the address bar.
There is a second difference, and it matters more. It is what happens when you repeat the request.
A GET is meant to be safe and repeatable. Asking for the same page twice should give the same result, and it should not change anything on the server.
A POST is meant to change something, such as placing an order or saving a comment. Sending it twice can well create two orders.
<!-- reads a page, the id travels in the address -->
<a href="/products?category=books">All books</a>
<!-- creates something, the values travel in the body -->
<form action="/orders" method="post">
<label for="sku">Product code</label>
<input id="sku" name="sku" required>
<button type="submit">Order</button>
</form>Two practical rules fall out of this.
You use the GET for anything that reads, and for anything that you want to be shareable or bookmarkable.
You use the POST for anything that writes. A search results page should be a GET, so that the visitor can copy the address and send it to someone else.
Quick reference
- The DNS turns a name into an address, and the connection is then opened to that address.
- A request is a method, a path, headers, and an optional body.
- The
200is a body, the304is a cached body, the404is a missing file, and the500is a broken server. - The https is the same protocol with the encryption and a certificate check.
- The browser requests the CSS, the JS, and the images after the HTML arrives, and that is where most of the wait happens.
Try it yourself: you open any site that you use, you open the network tab, you reload, and you sort the list by size. You find the biggest request on the page and you ask yourself whether it needs to be that big. Then you filter the list for the requests that failed, and you read the status codes one by one.