Leet School

{module 2}

What happens when you open a web page

How the web works, and your tools20 min read

What you will be able to do

  • Explain what a client, a server, a request and a response each are when a page opens.
  • Name the parts of a web address, and say which part chooses the computer and which chooses the page.
  • Watch a real page load in your browser's Network panel, and say whether a response arrived and what its status code was.

Why it matters

Zanzibar Spice Walks takes visitors on walking tours of the spice farms outside Stone Town, Tanzania. Most tourists find it through its web page. One Monday, Salma Hamad, the owner, heard from a hotel that the page "would not open". She called the person who built the page. He opened it on his laptop, saw nothing wrong, and said the fault must be her internet connection. Her internet company said the connection was fine.

Three days passed before anyone asked the hotel what the screen actually showed. The hotel's computer could not reach the internet at all. Salma lost three days of bookings to a problem that was never in her page.

Between typing an address and seeing a page, only a few things happen, and each one leaves a sign you can see. This lesson shows you those signs.

The idea

Two computers and one conversation

Every web page you have opened was sent to you by another computer. Two programs take part.

The client is the program that asks. Your browser is a client. The server is the program that waits for questions and answers them. The word "server" is also used for the computer it runs on.

The question the client sends is a request: "please send me this page". The answer the server sends back is a response. The client always speaks first. A server never sends a page that nobody asked for.

The parts of an address

A web address names exactly one thing on the web. Here is one, in its parts.

Part of https://www.zanzibarspicewalks.example/walksWhat it says
https://The rules for the conversation. The s means it is kept private
www.zanzibarspicewalks.exampleThe domain name: which computer to ask
/walksThe path: which page that computer should send

Computers find each other by number, not by name. So your browser first asks a directory service called DNS for the number that belongs to the name, as you look up a name in your phone to find a number.

The domain names in this course end in .example. That ending is kept for examples and never belongs to a real business.

What happens when you press Enter

  1. The browser looks up the number of the computer named in the address.
  2. It sends a request to that computer: "send me the page at this path".
  3. The server sends back a response.
  4. The browser reads the response and draws the page.

A response is text. Its first line holds a status code, a three-digit number that says how the request went. 200 means it worked. 404 means the server has no page at that path. The next lines are short facts about the response, called headers. Then comes an empty line, and after it the content: the page itself.

Three languages, three jobs

The content of a page is written in up to three languages. HTML says what each thing is, such as a heading:

From tour.html
<h1>Spice farm walk</h1>

CSS says how things look. This makes headings dark green:

From tour.css
h1 {
  color: darkgreen;
}

JavaScript says what the page does. This line writes a sentence into the page:

From tour.js
document.querySelector("#places").textContent = "6 places left for tomorrow.";

You do not need to read these yet. Modules 2, 3 and 4 teach one language each. Notice only this: each language usually lives in its own file, and the HTML names the other two. So one page means several requests, one for each file. Here is what the browser shows when the three files work together:

Output
Spice farm walk

6 places left for tomorrow.

The heading comes from the HTML and is green because of the CSS. The second line is not in the HTML at all. The JavaScript wrote it.

Worked example

Here is a whole response from the server of Zanzibar Spice Walks, as the text it really is. It answers a request for the home page:

response.txt
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 165

<h1>Zanzibar Spice Walks</h1>
<p>A three-hour walk through the spice farms outside Stone Town.</p>
<p>Walks leave at 9:00 every day except Friday. $25 a person.</p>

Read it from the top.

  • HTTP/1.1 is the version of the rules. 200 is the status code, and OK is its name.
  • Content-Type is a header. It says the content is HTML, so the browser draws it as a page.
  • Content-Length says the content is 165 characters long.
  • The empty line ends the headers.
  • After it comes the content: three lines of HTML. The words in angle brackets are called tags. <h1> marks a heading and <p> marks a paragraph.

Here is the content on its own, as a file called index.html:

index.html
<h1>Zanzibar Spice Walks</h1>
<p>A three-hour walk through the spice farms outside Stone Town.</p>
<p>Walks leave at 9:00 every day except Friday. $25 a person.</p>

This is the text the browser shows when it draws it:

Output
Zanzibar Spice Walks

A three-hour walk through the spice farms outside Stone Town.

Walks leave at 9:00 every day except Friday. $25 a person.

The tags are gone. The browser read them as instructions, not as words to show. The first line is large and bold because it is a heading. The status line and the headers are gone too: they were for the browser, not for the visitor.

See it in your own browser

You can watch the same conversation on any real page, in Chrome, Edge or Firefox.

  1. Open a page you know.
  2. Open the developer tools, a set of panels for looking inside a page. Press F12 or Ctrl+Shift+I on Windows or Linux, or Cmd+Option+I on a Mac. Lesson 4 teaches these panels properly.
  3. Click the tab named Network.
  4. Reload the page with F5 (Cmd+R on a Mac). Rows appear, one for each request.
  5. The first row is the request for the HTML. Its Status column should say 200. The Type column says what kind of file each row is, such as a document (the HTML), a stylesheet (CSS) or a script (JavaScript).
  6. Click the first row. A pane opens. Its Headers tab shows the status code and the headers. Its Response tab shows the content as text, like the worked example.

Common mistakes

Reading a 404 page as a broken server

Here is another response from the same server:

not-found.txt
HTTP/1.1 404 Not Found
Content-Type: text/html; charset=utf-8
Content-Length: 95

<h1>Page not found</h1>
<p>There is no page at this address on zanzibarspicewalks.example.</p>

The browser shows its content like any other page:

Output
Page not found

There is no page at this address on zanzibarspicewalks.example.

This does not mean the site is broken. The server is running, it received the request, and it answered: it has no page at that path. The fault is almost always in the address, such as a missing letter or an old link. Check the path first.

Blaming the page when nothing arrived

When no response arrives at all, the browser shows a message of its own with a short code. Here is the code when the computer has no internet connection:

Output
page: page.goto: net::ERR_INTERNET_DISCONNECTED at https://zanzibarspicewalks.example/

The start of the line comes from the tool that checked this lesson. The part that matters, ERR_INTERNET_DISCONNECTED, is the code Chrome and Edge print on the screen. There is no status code, because there is no response. Nothing in Salma's page could cause this. A status code comes from a server. A code that starts with ERR_ comes from the browser.

Think it through

Diego, a learner, opens a guesthouse's page. The text appears, but plain black on white, with no design. He wants to know what kind of fault it is before he writes to the guesthouse.

Understand. Something arrived, because there is text. He must find which part did not arrive.

Break down. One page can mean several requests. Did the HTML arrive? Did each file it names arrive?

Plan. Open the Network panel, reload, and read the Status column row by row.

Build. The first row, the document, says 200. One row of type stylesheet says 404.

Test. A stylesheet is CSS, which says how a page looks. A page with its CSS missing would look exactly like this. As an odd case, he opens another page of the same site. It looks right, and its stylesheet row says 200.

Reflect. He read no code. The status of each row told him the fault is one missing file on the server, not his connection. Next time he will open the Network panel before he guesses.

At work

A good question starts with saying exactly what you see. "The page does not open" can mean ten different things, and each points to a different person. The exact words on the screen point to one.

Compare two messages Salma could have sent:

The site is down again, please fix it.

At 10:15 on Monday, the hotel opened https://www.zanzibarspicewalks.example/walks in Chrome. The screen showed "No internet" and the code ERR_INTERNET_DISCONNECTED. On my phone the same address opens normally.

The second names the address, the browser, the time and the exact words, and it compares with another device. Anyone who reads it sees that the fault is the hotel's connection. Write what you see, not what you think it means.

Your tasks

Task 1: Watch a page load

Open a page of your choice, open the Network panel, and reload.

You are done when you have written down how many requests the page made, the status code of the first row, and the type of one other row.

Task 2: Take an address apart

Copy three addresses from your browser. For each, write down the rules part, the domain name and the path. If there is more after the path, such as a question mark and words, write "something after the path".

You are done when you have split all three, and can say which part chose the computer and which chose the page.

Task 3: Ask for a 404 on purpose

On a site you use, add /no-such-page-here after the domain name and press Enter, with the Network panel open. Then click the first row and find the content of the response in the Response tab.

You are done when you have seen 404 in the first row. Write two sentences to the site's owner: what you typed, and exactly what the screen and the Network panel showed.

Recap

  • A client, such as your browser, sends a request. A server sends back a response.
  • An address has the rules, the domain name, which chooses the computer, and the path, which chooses the page.
  • A response is text: a status line, headers, an empty line and the content. 200 means it worked, 404 means no page at that path.
  • HTML says what things are, CSS how they look, JavaScript what they do. Each file is one more request.
  • A status code comes from a server. A code that starts with ERR_ means no response arrived.

Go deeper