Tech Interview RoomStudy guides

Browser & Performance

What happens when you type a URL and press Enter?

Intermediate · 2 min read · Lesson 1 of 8 in Browser & Performance

  1. URL parsing: the browser decides whether it is a URL or a search, and checks the HSTS list to force HTTPS.
  2. Cache check: a service worker or the HTTP cache may answer immediately.
  3. DNS lookup: browser cache, OS cache, then a resolver turns the host into an IP address.
  4. Connection: TCP handshake plus TLS handshake (TLS 1.3 needs one round trip), or a single QUIC handshake for HTTP/3. ALPN agrees on HTTP/2 or HTTP/3.
  5. HTTP request with headers and cookies; the server (often a CDN edge) responds with status, headers and HTML.
  6. Parsing HTML into the DOM. The preload scanner spots CSS, scripts, images and fonts early and starts downloading them.
  7. CSS is parsed into the CSSOM. CSS is render-blocking: nothing paints until it is loaded.
  8. JavaScript: a classic <script> blocks parsing while it downloads and runs; defer runs after parsing in order; async runs as soon as it arrives; modules are deferred by default.
  9. Render tree: DOM + CSSOM, visible nodes only.
  10. Layout (reflow) computes positions and sizes, paint fills pixels into layers, and composite combines the layers on the GPU.
  11. The DOMContentLoaded and load events fire; the page becomes interactive once the main thread is free.

Where frontend engineers can help

Fewer round trips (CDN, HTTP/2 or 3, preconnect), less render-blocking CSS and JavaScript, smaller payloads, and caching.

Example

html
<head>
  <link rel="preconnect" href="https://api.example.com" crossorigin />
  <link rel="preload" href="/fonts/inter.woff2" as="font" type="font/woff2" crossorigin />
  <link rel="stylesheet" href="/app.css" />                     <!-- render-blocking: keep it small -->
  <script src="/app.js" type="module"></script>                 <!-- deferred automatically -->
  <script src="https://analytics.example.com/a.js" async></script>
</head>

Follow-up questions interviewers ask

Try answering each one before you open it.

What is the critical rendering path and how do you shorten it?

It is the sequence of steps from receiving HTML to the first pixels: HTML → DOM, CSS → CSSOM, render tree, layout, paint. Shorten it by inlining critical CSS for above-the-fold content, deferring the rest, using defer/async/modules for scripts, reducing the number and size of critical resources, and server rendering the main content.