How Websites Work?
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
When you view a website as a user, you view it in web browsers such as Chrome, Safari, Firefox, or Edge on your devices such as a laptop, tablet, or mobile. The devices and browsers are called clients.
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
HTTP (HyperText Transfer Protocol) is a protocol for transmitting hypermedia documents such as HTML. In other words, it enables the communication between the client (web browser) and the server (web server).
To access a website, you need to enter the URL in your browser (HTTP Request). The HTTP Request is transmitted to the web server hosting the website, and the web server sends website documents (HTML, CSS, JavaScript files) back to the web browser (HTTP Response).
URL
URL (Uniform Resource Locator) is an address of website resources. It usually consists of three parts.
- Communication protocol: informs the web browser that this is an HTTP request.
- Domain: informs the location of the web server with the domain name
- Resource path: informs location of data (website resource) within the web server
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.