Lesson 1 · Web development foundations

How the web actually works

DNS, HTTP, servers and browsers: what happens between a click and a page.

About 20 minutes

Tab indents. Press Escape, then Tab, to leave the editor.

Every web developer, whatever their title, works on one side or other of a conversation between two computers: a client (usually a browser) that asks for things, and a server that answers. Understanding that conversation is what lets you debug a slow page, read an error that says 404 or 502, or talk to a backend engineer without nodding along. This lesson walks through what really happens between typing an address and seeing a page.

Clients, servers and the internet in between

The internet is a global network of networks: cables, radio links and routers that pass small chunks of data called packets from one machine to another. The web is one thing that runs on top of it, a system of documents and apps fetched with a protocol called HTTP (HyperText Transfer Protocol). Email, video calls and game traffic use the same internet with different protocols.

A server is just a computer running a program that listens for requests and sends responses. It might be one machine in a closet or thousands of machines behind a load balancer. A client is anything that sends requests: a browser, a phone app, a command-line tool like curl, or another server.

Here is the whole journey, step by step. Use the diagram to walk through it at your own pace.

Lab

Loading a web page, step by step

Step through the journey. The diagram lights up the parts involved in each step.

BrowserHTTP cacheon your deviceDNS resolverWeb server203.0.113.10

Parse the URL

https://example.com/news?page=2 splits into a scheme (https), a host (example.com), a path (/news) and a query (page=2). Text that isn’t a URL becomes a search instead.

Step one: the URL

A URL (Uniform Resource Locator) tells the browser exactly what to fetch and how:

https://shop.example.com:8443/products/boots?size=10#reviews
  • https: is the scheme: which protocol to use. https is HTTP wrapped in encryption.
  • shop.example.com is the host: the name of the server.
  • 8443 is the port. It's usually left out, because https defaults to 443 and http to 80.
  • /products/boots is the path: which resource on that server.
  • ?size=10 is the query string: extra parameters, as key=value pairs joined by &.
  • #reviews is the fragment. It never leaves your browser; it tells the page where to scroll.

Browsers and JavaScript share a built-in parser for this, the URL class. You'll use it whenever you read or build addresses in code, so try it now.

Challenge

Take a URL apart

The starter code makes a URL object. Use console.log to print, one per line:

  1. the host name (url.hostname)
  2. the path (url.pathname)
  3. the value of the size query parameter (url.searchParams.get('size'))

Press Run and read the console under the preview.

Console
  1. Nothing logged yet.
  • You printed the host name, shop.example.com
  • You printed the path, /products/boots
  • You printed the size parameter, 10

Step two: finding the server with DNS

Computers on the internet are addressed by number, an IP address such as 203.0.113.42 (IPv4) or 2001:db8::42 (IPv6). Names are for humans. The Domain Name System (DNS) is the internet's phone book that turns a name into an address.

The browser first checks its own cache and the operating system's. If neither knows the answer, the request goes to a resolver, usually run by your internet provider or a public service, which asks the DNS hierarchy on your behalf: the root servers point to the servers for .com, which point to the servers for example.com, which give the final answer. Every answer comes with a TTL (time to live) that says how long it may be cached, which is why a DNS change can take a while to reach everyone.

Question

Quick check

A colleague says the site is "down", but it loads fine when you type its IP address directly. Which part of the journey is most likely failing?
Pick an answer.

Step three: connecting securely

With an IP address in hand, the browser opens a connection. For HTTP/1.1 and HTTP/2 that's a TCP connection, which guarantees bytes arrive complete and in order. On top of it, TLS (Transport Layer Security, the "S" in HTTPS) does two jobs: it encrypts everything, and it checks the server's certificate to prove the server really is shop.example.com and not an impostor on the café Wi-Fi.

The newest version, HTTP/3, runs over QUIC, a protocol built on UDP that combines the connection and encryption setup into fewer round trips. You rarely choose between these yourself; the browser and server negotiate the best one they both support. What matters for you: connection setup costs round trips, so a page that pulls files from ten different domains pays that cost ten times.

Step four: the request and the response

Now the browser and server finally talk HTTP. A request is a method, a path, and a set of headers (name and value pairs that describe the request). A response is a status code, its own headers, and usually a body. HTTP/2 and HTTP/3 send these as compact binary frames, but the meaning is the same as the readable HTTP/1.1 text below.

Step by step

One HTTP exchange, line by line

The browser sends a request

GET /products/boots?size=10 HTTP/1.1
Host: shop.example.com
Accept: text/html
Accept-Language: en-GB,en;q=0.9
User-Agent: Mozilla/5.0 (…)

GET means "give me this resource". The Host header says which site, because one server often hosts many. Accept says what formats the client understands.

1 / 6
Question

Quick check

Your app calls an API and gets back 403 Forbidden. Where should you look first?
Pick an answer.

Step five: turning bytes into a page

The browser reads the HTML from top to bottom and builds the DOM (Document Object Model), a tree of objects for every element. Along the way it finds references to other files: stylesheets, scripts, images, fonts. Each one is another HTTP request, often to the same connection. CSS becomes the CSSOM; the two combine to decide what every element looks like. Then the browser runs layout (where does everything go, how big is it) and paint (draw the pixels). Scripts can change the DOM at any time, which can trigger layout and paint again.

This is why a single "page load" might be dozens of requests, and why front-end performance work is mostly about sending fewer, smaller files and not blocking the first paint.

Where jobs fit on this map

  • Front-end developers own what happens in the browser: the HTML, CSS and JavaScript, how fast it renders and whether everyone can use it.
  • Back-end developers write the server code that turns a request into a response: reading databases, checking permissions, returning HTML or JSON.
  • DevOps and site reliability engineers keep the path in between healthy: DNS, certificates, load balancers, caches and servers.
  • Full-stack developers work across all of it.

Why this matters offline

When there's no connection, the journey breaks at the first network step: DNS can't resolve, so the browser shows an error page before HTTP even starts. Apps that keep working offline do it by answering requests without the network, from copies saved on the device. You'll build that idea up in the final lesson of this path.

Recap

  • A URL names the scheme, host, optional port, path, query string and fragment; the URL class parses it for you.
  • DNS turns a host name into an IP address, with caching at every level controlled by TTLs.
  • The browser connects over TCP and TLS (or QUIC for HTTP/3), then sends an HTTP request with a method, path and headers.
  • The response's status code family tells you where to look: 2xx success, 3xx redirect, 4xx the request, 5xx the server.
  • The browser parses HTML into the DOM, fetches sub-resources, then lays out and paints the page.

Finished this lesson?

Mark it complete to track your progress on this device.