Latency is time spent waiting. On a web interface, the wait between a user's action and the visible result is not one delay but a chain of them, each with a different cause and a different fix. This guide walks the chain from the user's tap to the rendered interface, then separates it into four categories that are measured and optimised differently.

The pipeline

The latency pipeline from user to rendered interface A vertical pipeline: User, DNS (hostname to IP, cached after the first lookup), Network (TCP and TLS handshakes or QUIC, one to three round trips), Origin or CDN (edge cache hit or origin compute; TTFB ends here), Browser (download, parse HTML and CSS, build trees; render-blocking resources), JavaScript (execute, hydrate, fetch APIs; long tasks block input), Rendered interface (layout, paint, composite; INP ends here). Stages are tagged network, server, rendering or interaction latency. Usertaps a link or controlDNShostname → IP addressNETWORKcached after first lookupNetworkTCP + TLS handshakes, or QUICNETWORK1–3 round tripsOrigin / CDNedge cache hit, or origin computeSERVERTTFB ends hereBrowserdownload, parse HTML/CSS, build treesRENDERINGrender-blocking resourcesJavaScriptexecute, hydrate, fetch APIsRENDERING / INTERACTIONlong tasks block inputRendered interfacelayout, paint, composite → frameINTERACTIONINP ends here
Latency pipeline. User → DNS → Network → Origin/CDN → Browser → JavaScript → Rendered interface. The right-hand labels show which latency category each stage belongs to and where TTFB and INP end.

1. DNS lookup

Before the browser can connect to example.com it needs the server's IP address. The lookup goes to the operating system's resolver, which may answer from cache or ask upstream DNS servers. A cold lookup on a mobile network can take tens to hundreds of milliseconds; a cached one takes effectively zero. Every distinct hostname on the page pays this once per session, which is one reason third-party assets on many hostnames are expensive. <link rel="dns-prefetch"> starts the lookup for a hostname the page will need later.

2. Connection: TCP, TLS, QUIC

With an address in hand, the browser opens a connection. Over HTTP/1.1 and HTTP/2 that means a TCP handshake (one round trip) followed by a TLS handshake (one more round trip with TLS 1.3). HTTP/3 runs over QUIC, which merges transport and encryption set-up and can resume a known server in zero round trips. A round trip to a server on another continent is often 150 to 300 milliseconds; to a nearby CDN edge it can be under 20. <link rel="preconnect"> performs DNS, TCP and TLS for a hostname ahead of the first request to it. HTTP/2 and HTTP/3 also multiplex many requests over one connection, so the per-request connection cost of HTTP/1.1 mostly disappears.

3. Server response

The request travels to the server, the server does whatever work the response needs, and the first byte of the response travels back. For a static file at a CDN edge this is a cache lookup. For a dynamically generated page it includes application code, database queries and template rendering. The sum of steps 1 to 3 is Time to First Byte (TTFB), and web.dev suggests keeping it at or under 0.8 seconds.

4. Asset download

Once the HTML arrives, the browser discovers stylesheets, scripts, images and fonts and requests them. Download time is bytes divided by bandwidth, plus the new connections for any new hostnames. Compression, modern image formats and sensible bundle sizes all act here; so does the browser's prioritisation, which fetches render-blocking CSS and the LCP image ahead of below-the-fold images. The asset guide covers the bytes; the CDN guide covers removing the download entirely with caching.

5. JavaScript execution

Scripts must be parsed, compiled and run before the code in them can respond to anything. For a gaming page this includes the page framework's hydration and the game runtime's boot. All of it runs on the main thread, and while it runs the interface is frozen even though it may already be painted. This is where a page that looks loaded still ignores the user's first tap.

6. API round trips

Interactions that need the server, such as loading a game's configuration, saving progress or fetching a leaderboard, pay the network again: a request to the API hostname and a response. Each round trip repeats a slice of steps 2 and 3. Keeping the API on the same origin as the page avoids a new connection; batching requests avoids repeated round trips; and showing the UI's response immediately while the request is in flight stops the user from perceiving the wait at all.

7. Rendering the result

Whatever JavaScript or the network produced now has to become pixels: style recalculation, layout, paint and compositing, then the display's next refresh. On a page with a large DOM or expensive styles this takes long enough to notice. It is the presentation delay component of Interaction to Next Paint.

Four kinds of latency

The pipeline stages group into four categories. Confusing them leads to fixing the wrong one.

CategoryStagesMeasured byReduced by
Network latencyDNS, connection, transfer time to and from the serverNavigation Timing and Resource Timing (DNS, connect, TLS, request/response phases)CDN edges near users, fewer hostnames, HTTP/2 or HTTP/3, preconnect, smaller payloads
Server latencytime the server spends producing the responseserver-side timing, Server-Timing header, TTFB minus network phasescaching at the edge and in the application, faster data access, pre-rendering
Rendering latencyparse, style, layout, paint, compositePaint Timing (FCP), LCP, Long Animation Framesless render-blocking CSS, smaller DOM, cheaper styles, compositor-only animation
Interaction latencyinput delay, handler time, next paintEvent Timing API, INPshorter tasks, yielding, workers, immediate visual feedback

Network and server latency are paid before the page exists. Rendering latency is paid at load and again on every change. Interaction latency is paid every time the user does something. A CDN fixes the first two and does nothing for the last two; a smaller JavaScript bundle helps the last two and barely touches the first.

User-perceived latency

What the user experiences is not the sum of the stages but the gap between doing something and seeing a response. That gap can be shortened without making anything faster. Immediate visual feedback on a tap, such as a pressed state or a spinner rendered in the same frame, makes a 400 millisecond server round trip feel acceptable; the same round trip with a frozen button feels broken. Skeleton layouts that reserve the final shape make a page feel loaded before its data arrives. Optimistic updates show the result of an action before the server confirms it. All of these are legitimate and widely used, and all of them depend on the main thread being free to paint, which brings the problem back to long tasks.

Measuring latency in the browser

The Navigation Timing API exposes timestamps for each phase of the document load: domainLookupStart and End, connectStart and End, secureConnectionStart, requestStart, responseStart (TTFB) and responseEnd. The Resource Timing API gives the same breakdown for every asset, provided cross-origin servers send the Timing-Allow-Origin header. The Event Timing API underlies INP and reports input delay, processing and presentation for each interaction. The Long Animation Frames API attributes slow frames to the scripts that caused them. Together they let a Real User Monitoring script tell you which of the four categories is the problem for real users, which no lab run can.

Example, not a measurement

A player taps "Play". Suppose the handler starts after 80 ms because a third-party script was running, takes 30 ms to update state, and the next frame paints 20 ms later. INP for that tap is 130 ms. The handler also fires a request to the API; the response takes 250 ms over a warm connection, and the game shows a loading state in the meantime. The perceived delay is 130 ms, not 380 ms, because the interface responded before the data arrived. These numbers are illustrative.

Sources

Primary documentation consulted for this guide. Thresholds and API behaviour were checked against these pages on 2026-11-02.

  1. Navigation timing — MDN Web Docs
  2. Navigation Timing Level 2 — W3C
  3. Resource timing — MDN Web Docs
  4. Time to First Byte (TTFB) — web.dev
  5. Optimize Time to First Byte — web.dev
  6. Connection management in HTTP/1.x — MDN Web Docs
  7. RFC 9110: HTTP Semantics — IETF RFC Editor
  8. RFC 9114: HTTP/3 — IETF RFC Editor
  9. Using dns-prefetch — MDN Web Docs
  10. rel=preconnect — MDN Web Docs
  11. Resource Hints — W3C
  12. Interaction to Next Paint (INP) — web.dev
  13. Long animation frame timing — MDN Web Docs
  14. Prioritized Task Scheduling API — MDN Web Docs