What happens when you type a URL and press Enter

· 2 min read

#how-it-works#web

Typing a URL and pressing Enter starts a chain of small, separate jobs. The one idea to keep: the browser first finds the server, then talks to it, then draws what it gets back.

The short version

A URL tells the browser three things: which protocol to use, which server to ask, and which resource to ask for. The browser looks up the server's address, opens a connection to it, sends a request, and turns the HTML in the reply into the page you see.

From pressing Enter to a page on screen The browser asks a DNS resolver for the server's address and gets an IP address back. It then opens a TCP and TLS connection to the web server, sends a GET request, receives HTML, and parses and renders the page. Browser 5 parse + render DNS resolver Web server 2 where is example.com? IP address 3 TCP + TLS handshake 4 GET / HTML
Numbers match the steps below (step 1 happens inside the browser). Solid arrows go out from the browser; dashed arrows are replies.

Step by step

  1. The browser reads the URL: https is the scheme, example.com the server, / the path. With no port written, HTTPS uses 443.
  2. It asks DNS for the server's IP address.
  3. It opens a TCP connection with a three-way handshake, then a TLS handshake that checks the server and sets up encryption.
  4. It sends an HTTP GET request for the page, and the server replies with headers and HTML.
  5. It parses the HTML into a tree (the DOM), fetches the CSS, scripts and images it finds, then lays out and paints the page.

Why it matters

Steps 2 to 4 are messages over the network, and all of them happen before you see a single pixel. That is why a slow DNS answer or a slow connection can delay a page that is itself small.

Sources