What Really Happens When You Hit Enter After Typing a URL?
The article breaks down the complete browser workflow from URL entry to page rendering, covering URL parsing, DNS lookup (recursive and iterative), TCP three‑way handshake, TLS negotiation, HTTP request/response exchange, and the final rendering steps, while also providing interview‑focused Q&A and a memorization mnemonic.
Interview Focus
Interviewers expect candidates to demonstrate a full‑chain understanding of how a browser fetches and displays a webpage, not just a superficial "DNS → TCP → HTTP" answer.
Core Answer
The process can be summarized in six major stages:
1. URL Parsing : The browser validates the input, distinguishes between a URL and a search term, auto‑completes the protocol (e.g., https://), and splits the URL into protocol, host, port, and path.
2. DNS Resolution : The domain name is translated to an IP address using recursive or iterative queries, typically over UDP port 53, with results cached at multiple levels (browser, OS, hosts file).
3. TCP Three‑Way Handshake : A SYN‑SYN/ACK‑ACK exchange establishes a reliable connection between client and server.
4. TLS Handshake (HTTPS) : If the target uses HTTPS, the client and server negotiate encryption keys (TLS 1.2 needs 4 round‑trips; TLS 1.3 reduces this to 1‑2).
5. HTTP Request & Response : The browser sends a GET request with headers (Host, User‑Agent, Cookie, Accept, etc.), the server processes it (potentially querying databases or micro‑services), and returns a status code and payload.
6. Browser Rendering : The HTML is parsed into a DOM tree, CSS into a CSSOM tree, they are merged into a render tree, layout is computed, and the page is painted. Scripts pause parsing; resources are fetched concurrently (≈6 parallel connections per host), and CDNs can serve static assets.
Detailed Breakdown
1. URL Parsing
When you type www.quanxiaoha.com and press Enter, the browser first checks whether the input matches a URL pattern; otherwise it treats it as a search query. If it is a URL, the protocol is auto‑filled (https://) and the components are extracted.
The browser also checks caches before sending any network request: its own DNS cache, the OS DNS cache (e.g., ipconfig /displaydns on Windows), and the hosts file. A cache hit skips the DNS lookup.
2. DNS Resolution
DNS translates the domain to an IP address. Two query modes exist:
Recursive query : The browser asks the local DNS server, which returns the final answer.
Iterative query : The local DNS server walks the hierarchy (root → TLD → authoritative) and aggregates the result.
Key points: DNS uses UDP port 53 by default; TCP is used only when responses exceed 512 bytes. Results are cached with a TTL.
3. TCP Three‑Way Handshake
The client sends SYN seq=x (state SYN_SENT). The server replies SYN+ACK seq=y, ack=x+1 (state SYN_RCVD). The client finalizes with ACK seq=x+1, ack=y+1, moving both sides to ESTABLISHED. Three handshakes prevent stale SYN packets from establishing unwanted connections.
4. TLS Handshake (HTTPS)
After the TCP connection, the client and server perform a TLS handshake to negotiate encryption keys. TLS 1.2 requires four round‑trips; TLS 1.3 reduces this to one or two, improving performance.
5. HTTP Request & Response
The browser sends a GET request with essential headers ( Host, User-Agent, Cookie, Accept, etc.). The server processes the request, possibly accessing databases or other services, and returns a status code (200, 301/302, 404, 500) and the response body.
If the server issues a 301/302 redirect, the browser repeats the entire flow for the new URL.
6. Browser Rendering
The HTML is parsed into a DOM tree; CSS into a CSSOM tree. They merge into a render tree (elements with display:none are omitted). Layout computes exact positions and sizes, then the paint step rasterizes pixels. Scripts ( <script>) block parsing until executed, which is why placing scripts at the end of <body> or using defer / async improves performance. Static resources are fetched concurrently (≈6 parallel connections per host), and CDNs serve them from edge nodes.
Frequent Interview Follow‑up
What protocol does DNS use and why? UDP port 53 by default because DNS messages are small; TCP is used only for large responses.
Why does TCP need a four‑way termination? Each direction is full‑duplex, so both sides must independently close their sending side with FIN/ACK.
Differences among HTTP/1.1, HTTP/2, HTTP/3?
HTTP/1.1: text protocol, one request per TCP connection (persistent connections can reuse).
HTTP/2: binary, multiplexed streams, header compression, server push.
HTTP/3: built on QUIC (UDP), eliminates TCP head‑of‑line blocking, faster connection setup.
What is CDN and its role? CDN caches static assets at edge nodes; DNS resolves the domain to the nearest CDN node, reducing latency and origin load.
When does TLS handshake occur? After the TCP three‑way handshake and before the HTTP request.
Memory Mnemonic
Six stages : 一解 (URL parsing) 二查 (DNS lookup) 三握 (TCP handshake) 四密 (TLS handshake) 五请求 (HTTP request/response) 六渲染 (browser rendering) .
Conclusion
This question tests a candidate’s depth of understanding of the entire network stack—from DNS resolution through TCP/TLS, HTTP exchange, and final browser rendering. In an interview, start with the six‑stage overview, then dive deeper into one or two stages you are most comfortable with.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architect Handbook
Focused on Java interview questions and practical article sharing, covering algorithms, databases, Spring Boot, microservices, high concurrency, JVM, Docker containers, and ELK-related knowledge. Looking forward to progressing together with you.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
