Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 37 ยท Network and Caching

HTTP Requests and Network Latency

Understand latency, bandwidth, round trips and connection costs, why many small requests hurt, and how to estimate download time and reduce the number of round trips.

Every file on a web page arrives through a network request. Two properties of the network decide how long that takes: latency (how long a message takes to travel) and bandwidth (how much data fits through per second). Most developers think only about bandwidth, but for typical web pages latency is the bigger problem.

This lesson separates the two, shows how to estimate transfer times, and explains what to do about request counts.

Latency versus bandwidth

  • Latency is the delay for one message to reach the server and a reply to come back. It is measured in milliseconds and described by round-trip time (RTT). It depends on distance, routing and the quality of the connection, not on file size.
  • Bandwidth is the data rate, measured in megabits per second. It decides how long a large file takes once the transfer is flowing.

A pipe analogy: bandwidth is the pipe's width, latency is the pipe's length. A wide pipe does not help when you only need a cupful through a very long pipe.

Connection Typical RTT Typical bandwidth
Fibre, same city 5 to 20 ms 500+ Mbps
Home broadband, far server 100 to 200 ms 50 to 200 Mbps
Good mobile (4G) 50 to 100 ms 10 to 50 Mbps
Weak mobile or congested Wi-Fi 200 to 500+ ms 1 to 5 Mbps

For small files (a few kilobytes), time is almost all latency. Going from 100 Mbps to 1 Gbps barely changes a page built of many small files; cutting the RTT does.

Estimating transfer time

A rough model for one request on a fresh connection:

TEXT
time = connection setup (DNS + TCP + TLS) + 1 RTT for the request/response + size / bandwidth
JS Estimate download time

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The 20 KB file takes about 1.25 s on the slow phone and is mostly connection setup (900 ms) plus one RTT (300 ms); bandwidth barely matters. A bigger file on a reused connection is dominated by transfer. The model is simplified (it ignores TCP slow start), but it shows where the time goes.

Why connections are expensive

A new connection to a new host requires DNS, a TCP handshake and TLS. That is several round trips before a single byte of your file moves. Two rules follow:

  1. Reuse connections. Keep-alive (the default in HTTP/1.1) and multiplexing (HTTP/2 and HTTP/3) let many requests share one connection.
  2. Use fewer hosts. Each extra hostname, such as an analytics domain, a font CDN and an image CDN, pays the setup cost again. Third-party origins often add 300 ms or more on mobile.

Request counts

In HTTP/1.1 a browser opens about six connections per host and each can carry one request at a time, so 60 small files queued up badly. That is why older advice said "bundle everything into one file". With HTTP/2 and HTTP/3, many requests share one connection and run in parallel, so bundling matters less, though each request still has overhead (headers, scheduling, caching metadata).

A practical balance today:

  • Avoid dozens of tiny files (for example 200 one-line JavaScript modules).
  • Avoid one giant bundle that every page must download. Split by route.
  • Inline very small critical assets, such as a few hundred bytes of CSS.
flowchart TD
  A["One request"] --> B{"New connection?"}
  B -->|Yes| C["DNS + TCP + TLS: 2-3 round trips"]
  B -->|No| D["Reuse: 0 extra round trips"]
  C --> E["1 round trip + transfer"]
  D --> E

Reusing a connection removes the setup round trips.

Seeing request timings

Group resource timing by type

In a real audit you would print the grouping (img, script, css, fetch) and the summed transferSize for each, to spot which category dominates.

Reducing latency's impact

  • Put content closer to users with a CDN.
  • Cut redirects and extra hostnames.
  • Use HTTP/2 or HTTP/3 (compression and protocols).
  • Hint early connections to critical origins with preconnect (resource hints).
  • Avoid request waterfalls where one file reveals the next.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. For a 5 KB file on a slow mobile connection, what dominates the time?

    Small files finish transferring almost instantly; waiting for round trips dominates.
  2. 2. What does RTT stand for?

    Round-trip time is how long a message takes to go to the server and back.
  3. 3. Why does each extra third-party hostname cost time?

    A new origin means a fresh connection with several round trips before data flows.
  4. 4. What is true of HTTP/2 compared with HTTP/1.1?

    Multiplexing lets many requests and responses share a single connection.

Summary

  • Latency (round trips) matters more than bandwidth for most web pages.
  • A fresh connection costs DNS, TCP and TLS round trips; reuse and fewer hosts save time.
  • HTTP/2 and HTTP/3 reduce the cost of many requests, but fewer and smaller is still better.
  • Move content closer, avoid redirects and chains, and hint critical origins.

Next: HTTP Caching Headers