What Happens When You Load a Web Page
When you type a web address and press enter, your browser looks up the site's numeric address through DNS, establishes a connection with the server using TCP, sends an HTTP request, and receives HTML that it reads and renders into a visible page on your screen.
Read along
The full Gist, word for word. The small numbers link to the sources for each fact.
You tap a few letters, press one key, and a whole page appears. What actually happens in that blink? It's a classic interview question, and one public GitHub project answers it at great length.2 Let's walk through it in three stages: before you hit enter, finding the right machine, and getting the page onto your screen.
First, consider what your browser is actually for. Its work comes down to two big tasks.5 It retrieves pages from web servers, and then it turns them into something you can see and interact with.5 It helps to separate the browser from the search engine.
A search engine is just another website, not the browser itself.5 The thing you type into the bar is called a URL, which is simply the address of the site you hope to reach.3 And the browser gets busy before you even finish typing. With every key you press, code inside the browser offers guesses about where you are headed and sharpens them as you go.2
It may even propose the full address before your fingers are done.2 Second, the browser has to find the right server. Here is a surprise. A name like the one you typed is not something a browser can send a request to.4
It needs a numeric IP address instead, so it first asks a system called DNS to translate the domain name.4 Think of DNS as a kind of address book: you look up the name, and you get back the number.1 Only with that IP address in hand can the browser go and fetch the site.1 The answer you get can depend on where you are.1
Large websites spread across multiple servers around the globe, so two people in different places might receive different IP addresses.1 Next, the browser and the server need to agree that they are ready to talk.4 That job falls to TCP, which uses a handshake made of three steps.4 Through those steps, each side confirms it is prepared both to send and to receive.4
Picture two people on walkie-talkies checking that they can hear each other before saying anything important. Third, the page itself has to arrive and appear. With the address found, the browser sends the server a message written in HTTP.1 In effect, that message says: please send me a copy of this website.1
If the server agrees, it answers with a status that reads two hundred, OK.1 Then the page comes back from the server in a form called HTML, and the browser has to make sense of it.5 Interpreting that HTML and showing the page on screen is called rendering.5 Interestingly, the browser does not wait for that download to finish before it starts working.4
It reads the HTML as a stream, putting together the page's building blocks, called nodes, while the rest of the document is still arriving.4 One last step can quietly help you later.3 After a visit, your device may hold on to parts of the page, a stash known as the cache.3 That way, the same site can load faster on your next trip.3
So the next time a page appears in a blink, remember how much had to go right first. Which part of that trip had you never pictured before?
Quick quiz
Lock it in: pick an answer to see if you got it.
1. What is the main reason DNS must translate a domain name before the browser can fetch a site?
Answer: Browsers cannot send requests to names, only to numeric IP addresses. Browsers require a numeric IP address to send requests; DNS translates the domain name into that address so the browser can locate and connect to the server.
2. How does the browser handle HTML as it arrives from the server?
Answer: It reads HTML as a stream, building page components while more data arrives. The browser streams HTML, constructing page nodes while the document is still being downloaded, rather than waiting for completion.
3. What happens after you visit a website that helps it load faster on your next visit?
Answer: Your device stores parts of the page in cache for reuse. The device caches portions of the page after your visit, allowing the same site to load faster when you return without re-downloading everything.
Sources
Every fact in this Gist is checked against these sources before it is published.
- How the web works - Learn web development | MDN
- GitHub - alex/what-happens-when: An attempt to answer the age old interview question "What happens when you type google.com into your browser and press enter?" · GitHub
- What is a URL - Tech Terms Explained - SDM Foundation
- How Browsers Work
- Browser Meaning & Definition | Brave
- World Wide Web - Wikipedia
Get a new Gist every day
1,000+ Gists on 37 topics in the GistWise app: a Gist of the Day every morning, quizzes, streaks and offline listening.
