FrontendEngineerIntern
Chapter 1 · Web fundamentals1.1 Client and server
Chapter 1

1.1

Client and server

When you open a web page, it comes to you from another computer. This section is about those two computers and what each one does.

ClientThe computer that asks for a web page. On your phone or laptop, the browser does the asking.

Every time you open a web page, two computers work together. One computer asks for the page. The other computer has the page and sends it. The one that asks is called the client. The one that sends is called the server.1

BrowserThe app you use to look at web pages. Chrome, Safari and Firefox are browsers.

Your phone, tablet or laptop is a client. To look at web pages, you use an app called a browser, such as Chrome, Safari or Firefox. When you open a page, your browser is the one doing the asking.

Most of the time the client is a browser, but not always. Other programs on your devices, like the apps on your phone, ask servers for things too.1

ServerA computer that keeps a website’s files and sends copies to anyone who asks.

A server is a computer that keeps a website’s files.2 A website is made of files, the same way your phone is full of photos and documents. Some files hold the words and the layout of the page. They are written in code called HTML, CSS and JavaScript. Other files are pictures and fonts. When a client asks, the server sends copies of those files.

One trip, start to finish

Opening a page happens in three steps:

  1. Your browser asks the server for the page.
  2. The server finds the files for that page.
  3. The server sends copies of the files back, and your browser puts them together into the page you see.

The asking has a name: a request. The answer has a name too: a response. Section 1.2 is all about those two.

Fig 1.1Client and serverTap a device3 clients, 1 server
Fig 1.1 Three clients share one server through a hub. Tap a device, or press 1, 2 or 3, to send a request and watch the files come back.

The server keeps its own files. It only ever sends copies, so it still has the page for the next person who asks. A busy server answers lots of clients at the same time, the way one kitchen cooks for a whole restaurant.

One page, many files

A web page is usually not one file. It is several. When you open a page, your browser first asks for the HTML file. The HTML tells the browser which other files the page needs: a CSS file for how the page looks, a JavaScript file for the parts you can click and use, and the pictures. The browser then asks the server for each of those files, one request for each.3 So opening one page can mean many requests.

Fig 1.2One page, many filesTap the monitor to load againOne page, 4 requests
ready0 of 4
Fig 1.2 Opening one page. Each capsule is one request: it goes up empty and comes back with one file. The page builds up as the files arrive, HTML first, then CSS, JavaScript and a photo. Tap the monitor to load the page again.

What is inside a server

HTTP serverThe program on a server that waits for requests and sends back files.

A server is two things working together. The first is the computer itself, the machine you could touch. The second is a program running on that computer, called an HTTP server. The HTTP server waits for requests, finds the right file and sends a copy back.2

How a server finds a file

404 Not FoundThe error a server sends back when it does not have the file you asked for.

Every request asks for one file by its name. The HTTP server looks for a file with that name. If it has the file, it sends a copy. If it does not have it, it still answers, but the answer is an error that says the file was not found. That error is called 404 Not Found.2

Fig 1.3Inside the serverAsk for a file4 files stored
index.htmlWaiting
Fig 1.3 Inside the server. The picker does the HTTP server’s job. Ask for a file and it runs to that file’s card. A card there means a copy goes out. An empty slot means the answer is 404 Not Found.

Where servers live

Hosting companyA company that keeps your website on its servers for you, usually for a fee.

You could turn your own computer into a server, but most websites are not kept that way. A home computer gets switched off, and its address on the internet can change. So people usually pay a hosting company to keep their website on a server that stays on, keeps the same address, and is looked after for them.2

Data centreA building full of servers, with backup power, cooling and internet connections.

Hosting companies keep their servers in buildings called data centres. Inside, servers sit in tall cabinets called racks. A data centre has backup power for when the electricity fails, cooling to stop the machines getting too hot, and fast connections to the internet.4

Fig 1.4Where servers liveTap a server6 servers in this rack
Fig 1.4 A corner of a data centre. Tap a server, or pick one below, to slide it out and see which websites it keeps. The servers are numbered from the bottom, and one server can keep many websites.

Worth knowing

  • A server is a normal computer. Most servers have no screen. They stay switched on day and night, so they can answer whenever someone asks.2
  • A server and a website are not the same thing. The website is the files. The server is the computer that keeps them, and one server can keep many websites.2
  • Client and server are jobs, not special kinds of computer. Later in this course you will turn your own laptop into a small server, and the browser on that same laptop will be its client.

Exercises

Answer from memory. Scrolling up first only makes it feel easier.

  1. 1You open a news website on your phone. Which one is the client?

  2. 2What does a server do when a client asks for a page?

  3. 3You open one web page. How many requests does your browser usually send?

  4. 4A client asks for a file the server does not have. What comes back?

  5. 5Why do most servers stay switched on all day?

  6. 6Why do most websites live on servers at a hosting company?

  7. 7Can your laptop be a server?

0 of 7 right

Sources

  1. 1How the web worksMDN Web Docs. Clients, servers and the parts in between.
  2. 2What is a web server?MDN Web Docs. What a server keeps, how it answers, and why websites use hosting.
  3. 3How browsers load websitesMDN Web Docs. Why one page means several requests.
  4. 4Data centerWikipedia. What a data centre is and what keeps it running.

Something still unclear? Ask a question on GitHub.

PreviousChapter 1 contents
Next1.2 Request and responseComing soon