How the Web Works¶
The first web browsers appeared in the early 1990s, stemming from a 1989 proposal from a computer scientist at CERN named Tim Berners-Lee. Overall a somewhat modest proposal compared to what the web has become, it ends with the bold proclamation:
"We should work toward a universal linked information system, in which generality and portability are more important than fancy graphics techniques and complex extra facilities."
This proposal led to the flurry of new technologies we now recognize as the web: protocols like HTTP for communication between devices, languages like HTML for instructing the browser what to show and do. The fundamental building blocks of the web have existed since the 1990s. While each has evolved over the past few decades, each continues to serve the purpose it did in the earliest days of the web.
What is a Server?¶
"The server is down." "They're upgrading the server."
I've had half a dozen friends ask me in a quiet whisper "What is a server?"
A server is, put simply, a computer that is plugged into the internet somewhere and (probably) left on 24/7. The web can be thought of as conversations between these computers.
One way for us to interact with the web is to use our web browser as a client to ask questions of these servers. We might do this by typing in a URL or clicking a link to one.
If you'd like to understand the server role better, it may be helpful to read Static or Dynamic?.
URL: Location¶
URLs have become a part of everyday life. So much so we use them all the time without considering why they are comprised of specific repetitions and symbols:
http://example.com/
https://kagi.com/?q=search+term&lang=en
https://www.view-source.org/how-the-web-works/#url-describing-a-location
A URL consists of distinct parts:
- protocol (
https://): An agreement between the client and server on how they will communicate. - domain name (
www.view-source.org): Name of the server to communicate with. - path (
/how-the-web-works/): Identifies a distinct "page" from the server. - query string (
?q=search+term&lang=en): Additional parameters sent to the server, often from a form. - fragment (
#url-describing-a-location): Specifies a part of the page to link to.
Entering a URL into your web browser triggers a sequence of steps which we'll explore below.
sequenceDiagram
actor You
participant B as Browser
participant D as DNS
participant S as Server
You->>B: Enter URL (view-source.org/http/)
B->>D: Where is view-source.org?
D-->>B: IP address 192.0.2.1
B->>S: HTTP GET /http/
S-->>B: 200 OK + HTML
Note over B: Parse HTML,<br/>find CSS, JS, images
B->>S: GET style.css, app.js, logo.svg
S-->>B: CSS, JS, images
Note over B: Apply CSS,<br/>run JavaScript
B-->>You: Rendered page
DNS: Finding the Server¶
The first thing that your browser has to do when you enter a URL is decide who to ask for the content.
Using the domain name, the browser makes a request to an internet service known as the domain name system or DNS.
DNS can be thought of as the index that makes the web possible. Your computer queries it with a request like "What server should I visit to access www.view-source.org?" and DNS replies with an IP address, typically a dotted set of four numbers like 192.0.2.1.
IP addresses route requests to specific servers. DNS functions like a phone book, mapping memorable names to hard-to-memorize IP addresses.
HTTP(S): Asking for the Page¶
With the server identified, the browser can now make an HTTP request.
HTTP is a simple agreed-upon protocol for web browsers and other clients to ask servers for information, and for the server to send a structured response.
For a request to www.view-source.org/how-the-web-works/ the server replies with an HTML document. Most URLs will result in either an HTML file, another file the page uses (CSS, images), or some kind of data (CSV, JSON).
If you're looking to dive deeper into the web technologies, HTTP is the best starting point.
HTML: Structure¶
HTTP was primarily designed for servers to reply with structured documents that would appear in the browser. Pages, like this one, are structured into paragraphs, sections, headers, and more using a language called HTML.
Understanding how actual websites are structured begins with HTML.
HTML pages often reference additional files: images, CSS, and JavaScript files. Each of these will be fetched by the browser with additional HTTP requests.
CSS: Style¶
HTML focuses on structure, but most webpages use custom styling for branding or other design goals. The actual visual appearance of a page is largely dictated by CSS, a language that complements HTML's structure with powerful visual design features.
After you have a basic understanding of HTML, you can explore CSS.
JavaScript: Interaction¶
HTML and CSS are declarative languages. They suggest what is to be shown, but leave it up to the browser to accomplish that goal. Some forms of interaction—clicking links, submitting forms—are fundamental to how the web works and can be described in HTML and handled by browsers.
JavaScript enables websites and applications to define their own additional interactions. If a page should load more content when the user scrolls, or continuously update the screen without interaction—JavaScript comes into play.
JavaScript is an overview of the language and its unique relationship to the browser. It is intended primarily for those who have written code in other languages before.
And More¶
To load a page like this one, your browser looks up the domain with DNS, requests HTML via HTTP, and follows up with requests for CSS, JS, and more.
The modern web has moved far past merely serving linked documents and has grown beyond the core web technologies.
- SVG allows scalable, programmatic vector graphics defined in a language that interoperates with HTML/CSS/JS.