How Websites Work?
Understanding how websites function is essential for anyone learning web development. Websites operate through a logical interaction between clients, servers, and various protocols. To understand the mechanism of websites, you need to become familiar with some basic concepts:
- Client and Server
- HTTP
- URL
- IP Address and Domain
Client and Server
Client
The client is the device and browser used to access a website. Examples include Chrome, Safari, or Firefox on devices like laptops, tablets, or smartphones. The client requests content from a server and displays it to the user.
Server
A website can be located anywhere in the world. The server can be a physical server or a virtual server. To host a website, a web server (software such as Apache and Nginx) is typically installed on the physical or virtual server. A website owner can publish a website by locating website documents such as HTML, CSS, and Javascript files on a web server.
HTTP (HyperText Transfer Protocol)
HTTP is the protocol that governs the communication between clients and servers. It facilitates the transfer of hypermedia documents like HTML files.
How HTTP Works:
- The client sends an HTTP Request by entering a URL in the browser.
- The server receives the request and processes it.
- The server sends an HTTP Response, which includes the requested website files, to the browser.
This seamless communication ensures that users can access websites quickly and efficiently.
URL (Uniform Resource Locator)
A URL is the address used to locate resources on the internet. It typically consists of three parts:
- Communication Protocol: Indicates that the request uses HTTP or HTTPS (secure HTTP).
- Domain Name: Specifies the server’s location using a human-readable address
- Resource Path: Identifies the specific file or resource on the server (e.g., /index.html).
The URL serves as a bridge between the user and the resources they want to access.
IP Address and Domain
An IP address is a unique address that identifies a device on the internet. (IP addresses are also used in local networks). As the IP address is a combination of numbers, memorizing it can be hard for humans. To solve this problem, the domain plays a role.
The domain is a conversion of an IP address, and the domain information (the mapping of domains and IP addresses) is stored on the DNS Server (Name Server).
The illustration on the main figure is a simplified flow of HTTP requests and responses. In detail, there are four key steps when a website user browses web pages like the illustration below.
- When a website user enters a URL in their browser, the data is sent to DNS Server (Name Server) nearby
- The DNS server provides an IP address registered for the domain
- With the IP address, the HTTP request is directed to the web server
- Finally, the web server returns an HTTP Response to the website user's browser
Understanding this concept is important when you publish your website with your own domain. We’ll cover how to publish a website in the last chapter of this course.