⇦ Back

WDX-180

Web Development X

How the web works

(Updated: 17/08/2023)

How the web works provides a simplified view of what happens when you view a webpage in a web browser on your computer or phone.

This theory is not essential to writing web code in the short term, but before long you’ll really start to benefit from understanding what’s happening in the background.

Clients and servers

Computers connected to the internet are called clients and servers. A simplified diagram of how they interact might look like this:

Two circles representing client and server. An arrow labelled request is going from client to server, and an arrow labelled responses is going from server to client

The other parts of the toolbox

The client and server we’ve described above don’t tell the whole story. There are many other parts involved, and we’ll describe them below.

For now, let’s imagine that the web is a road. On one end of the road is the client, which is like your house. On the other end of the road is the server, which is a shop you want to buy something from.

A black-and-white photo of a person crossing a road at a crosswalk

In addition to the client and the server, we also need to say hello to:

A protocol is a system (or set) of rules that define how data is exchanged within or between computers. Communications between devices require that the devices agree on the format of the data that is being exchanged.

So what happens, exactly?

When you type a web address into your browser (for our analogy that’s like walking to the shop):

  1. The browser goes to the DNS server, and finds the real address of the server that the website lives on (you find the address of the shop).
  2. The browser sends an HTTP request message to the server, asking it to send a copy of the website to the client (you go to the shop and order your goods). This message, and all other data sent between the client and the server, is sent across your internet connection using TCP/IP.
  3. If the server approves the client’s request, the server sends the client a “200 OK” message, which means “Of course you can look at that website! Here it is”, and then starts sending the website’s files to the browser as a series of small chunks called data packets (the shop gives you your goods, and you bring them back to your house).
  4. The browser assembles the small chunks into a complete web page and displays it to you (the goods arrive at your door — new shiny stuff, awesome!).

Order in which component files are parsed

When browsers send requests to servers for HTML files, those HTML files often contain <link> elements referencing external CSS stylesheets and <script> elements referencing external JavaScript scripts. It’s important to know the order in which those files are parsed by the browser as the browser loads the page:

DNS explained

Real web addresses aren’t the nice, memorable strings you type into your address bar to find your favorite websites. They are special numbers that look like this: 192.0.2.172.

This is called an IP address, and it represents a unique location on the web. However, it’s not very easy to remember, is it? That’s why the Domain Name System was invented. This system uses special servers that match up a web address you type into your browser (like “mozilla.org”) to the website’s real (IP) address.

Websites can be reached directly via their IP addresses. You can use a DNS lookup tool to find the IP address of a website.

Packets explained

Earlier we used the term “packets” to describe the format in which the data is sent from server to client. What do we mean here? Basically, when data is sent across the web, it is sent in thousands of small chunks. There are multiple reasons why data is sent in small packets. They are sometimes dropped or corrupted, and it’s easier to replace small chunks when this happens. Additionally, the packets can be routed along different paths, making the exchange faster and allowing many different users to download the same website at the same time. If each website was sent as a single big chunk, only one user could download it at a time, which obviously would make the web very inefficient and not much fun to use.

Here’s a nice visual representation of how an image will be split in packets, send across the Internet to a client that requested the image and then reassembled back into a full image:


Project maintained by Behsolo Hosted on GitHub Pages — Theme by mattgraham