Build Your Own Web

Background lesson · How the web works · 45–60 minutes

What happens when you press Enter?

You type an address, press Enter, and a page appears in about a second. In that second your browser asked a stranger for directions, opened a locked line to a computer that may be on another continent, asked for one file, then went back for a dozen more. This lesson slows that second down so you can watch every step.

You do not need this to write your first page. You do need it the first time your published site shows a blank screen, a padlock warning, or a 404, because each of those is one step in this trip going wrong.

By the end you can

  • Name every part of a URL and say which computer reads each part.
  • Explain what DNS does and why a typo in a domain gives a different error from a typo in a filename.
  • Read an HTTP request and response, including the status code.
  • Explain what the padlock in HTTPS does and does not promise.
  • Find every request your own site makes, using the Network tab.

Fits before Lesson 1 as a big picture, or before Lesson 9 when your site goes live.

The big picture: clients, servers and an address book

The web is a conversation between two kinds of computer. Your browser is the client: it asks. A web server is a computer that waits for requests and answers them by sending files. Nothing on the web arrives unless a client asked for it first.

Computers on the internet find each other by number, an IP address such as 185.199.108.153. People are bad at remembering numbers, so we use names like github.io instead. The Domain Name System is the internet's address book: it turns a name into a number. The internet is the roads; the web is one kind of traffic on those roads, alongside email, games, and video calls.

Pause: name one physical thing the internet is made of, and one rule (protocol) computers must agree on to use it.

Watch for the difference between the internet (the network of connected computers) and the web (pages and links that travel over it).
The steamship Great Eastern laying the transatlantic telegraph cable in 1866
Laying the Transatlantic Cable (SS Great Eastern, 1866) The physical origin of intercontinental networks. In 1866, the giant steamship Great Eastern successfully coiled and submerged 2,400 miles of telegraph cable across the Atlantic abyss. For the first time, text messages crossed between continents in minutes rather than weeks, proving that global communication requires heavy physical subsea infrastructure. Credit: Robert Dudley / Metropolitan Museum of Art / Wikimedia Commons · Public domain · source
Diagram showing the protective concentric layers of a modern submarine fiber-optic communications cable
Anatomy of an Undersea Fiber-Optic Cable Today, over 95% of international internet traffic travels through undersea cables. Beneath outer polyethylene jackets, copper power conductor tubes, and steel tensile armoring lie hair-thin strands of high-purity glass fiber transmitting petabits of web requests across ocean floors via modulated laser pulses. Credit: Wikimedia Commons · CC BY-SA 3.0 · source

Lab 1 — Take an address apart

A URL packs several instructions into one line. Different computers read different parts: DNS reads only the domain, the server reads the path and query, and the fragment never leaves your browser at all.

    Try: delete the s from https, remove the path, then type an address with a space in it. What does each part's "who reads it" line say now?

    Lab 2 — One request, step by step

    Here is the whole trip for one page. Step through it, then flip one of the switches and run it again. Each switch is a real fault students hit when they publish.

    Change one thing
     

      Reading the server's reply

      Every HTTP response starts with a three-digit status code. The first digit tells you who has the problem: 2 means it worked, 3 means "look somewhere else", 4 means the request was wrong, 5 means the server broke.

      Status codes you will actually meet
      CodeMeaningWhen you will see it
      200 OKHere is the file you asked for.Every working page, image and stylesheet.
      301 Moved PermanentlyThat file lives at a new address now; go there.Typing http:// on a site that forces https://.
      304 Not ModifiedYou already have the newest copy; use it.Reloading a page whose files have not changed.
      404 Not FoundThe server is there, but nothing lives at that path.A misspelled filename, or Photo.JPG versus photo.jpg.
      500 Internal Server ErrorThe server crashed while answering.Rare on GitHub Pages, which only hands out files and runs none of your code.

      A 404 and a "site can't be reached" error are different steps failing. 404 means DNS worked, the connection worked, and the server answered: only the path was wrong. "Can't be reached" means the trip never got that far, usually because the domain name is wrong.

      The padlock: what HTTPS promises

      HTTPS is HTTP sent through an encrypted tunnel. Before any page is sent, your browser and the server agree on a secret key, and the server proves who it is with a certificate signed by an organisation your browser already trusts.

      The padlock does mean

      • Nobody on the Wi-Fi or along the route can read what you send or receive.
      • Nobody along the way can change the page before it reaches you.
      • You are connected to the domain shown in the address bar.

      The padlock does not mean

      • The site is honest. A scam site can have a padlock too.
      • The domain is the one you meant. paypa1.com can have a valid certificate.
      • Your information is safe once it arrives. That depends on the people running the server.

      GitHub Pages gives every site HTTPS for free. Leave "Enforce HTTPS" switched on in your repository's Pages settings.

      Claude Shannon, father of Information Theory, at Bell Laboratories
      Claude Shannon: Information Theory & Cryptography (1948) Claude Shannon at Bell Laboratories. His 1948 paper A Mathematical Theory of Communication introduced the “bit” and established the theoretical limits of digital transmission, compression, and mathematical secrecy. Modern HTTPS encryption protocols rely directly on Shannon's mathematical formulation of information entropy and perfect secrecy. Credit: Bell Laboratories / MIT / Wikimedia Commons · Public domain · source
      Three-rotor military Enigma cipher machine with open lid showing keyboard, lampboard, and scrambler wheels
      The Mechanical Roots of Encryption (Enigma Cipher Machine) Early mechanical ciphers used rotating internal wiring rotors to transform plaintext letters into pseudo-random ciphertext. Modern web protocols like Transport Layer Security (TLS/HTTPS) replace physical rotors with asymmetric public-key algorithms and symmetric AES ciphers, guaranteeing that eavesdroppers on Wi-Fi or internet backbone lines cannot decrypt or tamper with web traffic. Credit: Wikimedia Commons · CC BY-SA 3.0 · source

      Packets: how a file actually travels

      A web page does not travel in one piece. It is cut into packets of about 1,500 bytes, each labelled with where it is going and its place in the sequence. Routers pass each packet one hop closer to its destination, and different packets may take different routes. Your computer puts them back in order and asks again for any that went missing.

      Arrived (in the order they came)

        Rebuilt by sequence number

        ARPANET logical map from March 1977: boxes for host computers joined by lines across the United States
        ARPANET, March 1977. The internet's ancestor connected a few dozen university and government computers. It was built on packet switching, so a message could route around a broken line instead of failing. Every packet you send today still works this way. DARPA, via Wikimedia Commons · Public domain
        Cut-away of an optical fibre cable showing protective layers around thin glass fibres
        The internet is mostly glass. Packets crossing oceans travel as pulses of light inside hair-thin glass fibres, bundled in cables laid on the sea floor. "Wireless" only describes the last few metres to your device. Optical fibre cable, via Wikimedia Commons · CC BY-SA 3.0
        A black NeXT cube computer in a museum case, with a handwritten label on its side
        The first web server (CERN, 1990). Tim Berners-Lee ran the first website on this NeXT computer. The sticker on its side reads "This machine is a server. DO NOT POWER IT DOWN!!" — because if someone switched it off, the whole web went dark. Today one popular site may run on thousands of servers in many countries. Coolcaesar, via Wikimedia Commons · CC BY-SA 3.0

        Try it on your own site: the Network tab

        Your browser records every request it makes. Open the developer tools (F12, or right-click → Inspect) and choose the Network tab, then reload the page.

        1. Find the first row. It is your HTML file. Its status should be 200.
        2. Count the rest. Each stylesheet, script, image and font is its own request, discovered only after the HTML arrived.
        3. Look for red rows. Red usually means 404: the file your HTML names does not exist at that path.
        4. Reload again. Notice files marked as coming from the cache, or 304. They were not downloaded again.
        5. Read one request. Click a row and find the request method, the status code, and the response headers you saw in Lab 2.

        Check: you can say how many requests your page makes and which one is the largest. Repair: fix any red row by matching the filename in your HTML to the real file, letter for letter.

        Check your understanding

        1. You type mayacodes.github.io but the real site is maya-codes.github.io. Which step fails?

        2. Which part of https://site.org/about.html#team is never sent to the server?

        3. A page loads as plain black text with no colours. The HTML returned 200. What is the most likely cause?

        4. A site has a padlock. What can you be sure of?

        Checkpoints