What Happens When You Type a URL
Between pressing Enter and seeing a page, about eight things happen in under a second. Understanding them explains most of the internet problems you will ever debug.
You type an address, press Enter, and a page appears. The gap between those two events is about half a second and involves at least six separate systems, any of which can fail independently.
Knowing the sequence is what turns a vague sense that the internet is broken into a specific diagnosis.
Step one: the name means nothing to the network
Computers do not route traffic by name. They route by number β an IP address. So the first task is translation: turning the name you typed into a number.
That is DNS, the domain name system, and it is best understood as a distributed phone book. Your computer asks a resolver, the resolver asks higher authorities, and the answer comes back as an address.
This is why a site can be "down" while its server is perfectly healthy. If DNS is broken, you never reach the server at all.
Step two: the connection
With an address in hand, your computer opens a connection to that machine. For a normal website this is TCP, which handles the unglamorous work of getting bytes across the network in order and without gaps.
Then TLS layers encryption on top, which is the padlock in the address bar. TLS also verifies that the server is who it claims to be, using a certificate signed by an authority your browser already trusts.
A certificate error is therefore a statement about identity, not about the content. The browser is saying it could not confirm who it is talking to.
Step three: the request
Now the browser sends an HTTP request. In its simplest form it names three things: a method β usually GET for reading β a path such as /library.html, and a header block containing cookies, the browser version, and what formats it will accept.
The method matters. GET asks for something and should not change anything. POST submits data. A site that changes data on a GET request is a site that will eventually break, because browsers and crawlers retry GETs freely.
Step four: the server decides
On the other end, a server receives the request and produces a response. It might read a file, query a database, run application code, or forward the request somewhere else.
The status code it returns is the single most useful diagnostic in web debugging:
- 200 β fine, here is the content.
- 301 or 302 β it moved, follow this other address.
- 404 β nothing here at this address.
- 500 β the server broke while handling your request.
The difference between 404 and 500 is the difference between "you asked for the wrong thing" and "we failed to answer correctly", and knowing which one you have halves the work.
Step five: the response body
For a normal page the body is HTML: the structure of the document, plus links to CSS for appearance and JavaScript for behaviour.
The browser parses the HTML, discovers the CSS and JavaScript references, and requests those too. This is why one page load produces dozens of requests in the developer tools β and why a single slow external script can delay a page that otherwise arrived instantly.
Step six: rendering
The browser builds a model of the page, calculates the position and size of everything, and paints it to the screen. JavaScript can then modify the page after it is drawn, which is how modern sites update without a full reload.
A page that looks blank and then fills in is doing exactly this. A page that never appears at all failed somewhere before this step.
Step seven: caching, which is everywhere
Almost every step so far has a cache. Your browser caches DNS answers and files. Your network caches DNS. The server caches responses. Content delivery networks cache copies of pages close to you geographically.
This is why "it works on my machine" and "it is broken for the client" can both be true, and why a hard refresh or a cache clear is such a common fix.
Step eight: the browser asks again, quietly
Many requests you did not make. The browser requests a favicon, analytics scripts fire, and browsers increasingly pre-resolve DNS for links you might click.
This is also how most tracking works: third-party requests that go to a different domain than the one in the address bar.
The bottom line
DNS resolves the name, TCP and TLS open a secure connection, HTTP carries the request, the server produces a status code and a body, and the browser renders it. Eight steps, and each one fails in a recognisable way. Learning to tell them apart is what makes you able to debug a website instead of guessing β and Designing Data-Intensive Applications is where the server side of this story continues.
π Recommended reading
Print editions of books covered on this site that go deeper into this topic.
See all 10 books ranked in βBest Programming Books for Developersβ β