# "Document request latency": how to fix it in Lighthouse

**Audit ID:** `document-latency-insight` · **Category:** Performance

<!--QA-->
> **Quick answer:** Document request latency is the Lighthouse 13 insight that checks the first request for your HTML. It fails if the page redirects, if the server takes more than 600 ms to respond ("Server responded slowly"), or if the HTML is sent without gzip or Brotli. Fix it by linking to the final URL, caching the HTML at the edge, and enabling compression.
<!--/QA-->

This Lighthouse 13 insight checks one request: the first one, for your HTML document. Nothing else on the page can start until that HTML arrives. The browser cannot discover your CSS, scripts, fonts or the LCP image before it has the document. So every millisecond spent on redirects, on a slow server, or on downloading uncompressed HTML is added to [First Contentful Paint](/audits/first-contentful-paint) and [Largest Contentful Paint](/audits/largest-contentful-paint). The insight runs three checks and fails if any one of them fails. In our study of 269 Shopify storefronts, 53 of them (19.7%) failed it. This page covers what each check measures, what "Server responded slowly" means, and the fixes for each.

## TL;DR

- **What:** A checklist for the HTML request: **Avoids redirects**, **Server responds quickly** (under 600 ms), and **Applies text compression**. The failing versions read "Had redirects", "Server responded slowly (observed N ms)" and "No compression applied".
- **Why it matters:** It is the first link in every request chain. A slow document request delays every later request by the same amount.
- **Fix:** Link to the final URL so there are no redirects. Cache the full HTML at a CDN or with a page cache so the server answers fast. Turn on Brotli or gzip for `text/html`.

## What does "Document request latency" mean?

The insight looks at the main document request in the page load trace and reports three checks:

| Check | Passes when | Failing text in the report |
|---|---|---|
| **Redirects** | The browser reached the final URL with no redirect | `Had redirects (2 redirects, +630 ms)` |
| **Server response time** | The server answered in 600 ms or less | `Server responded slowly (observed 1,240 ms)` |
| **Text compression** | The HTML was sent with gzip, Brotli or another encoding, or compression would save under 1,400 bytes | `No compression applied` |

Server response time here is the wait between the browser sending the request and the first byte of the response arriving, often called time to first byte (TTFB). It is time your server or platform spends building the page, plus the trip to the server. It does not include downloading the HTML.

The 600 ms limit is a pass line, not a target. The Chrome team chose 600 ms to avoid false failures under throttled runs, and the insight estimates savings against a target of 100 ms. A server that answers in 500 ms passes the check and still leaves time on the table.

## Is this the same as "Reduce initial server response time"?

Yes, and more. Lighthouse 13 folded three older audits into this one insight:

| Older audit (Lighthouse 12 and earlier) | Now the check |
|---|---|
| Reduce initial server response time (`server-response-time`) | Server responds quickly |
| Avoid multiple page redirects (`redirects`) | Avoids redirects |
| Enable text compression (`uses-text-compression`) | Applies text compression (for the HTML) |

Older tools, plugins and blog posts still print the old titles. The fixes did not change. One difference: this insight checks compression on the HTML document only. Compression of your CSS and JavaScript is covered on the [Enable text compression](/audits/enable-text-compression) page.

## Does Document request latency affect my Performance score?

Not directly. Insights carry no weight in the Lighthouse 13 Performance score. The cost shows up in the metrics. Lighthouse estimates the savings as the server time above 100 ms plus the redirect time, and applies that same amount to both FCP and LCP. A 1,200 ms server response and one 300 ms redirect is roughly 1.4 seconds off both metrics.

## How do I fix "Server responded slowly"?

### 1. Cache the full HTML

The biggest win is to stop building the page on every request. Serve the finished HTML from a cache:

- **A CDN with HTML caching:** Cloudflare (Cache Rules or APO for WordPress), Fastly, CloudFront, or your host's edge cache. Cache the HTML for anonymous visitors and bypass the cache for logged-in users, carts and checkouts.
- **A page cache on the server:** WordPress caching plugins write each page to a static file or memory and skip PHP and the database on later requests.
- **Static or incremental rendering:** frameworks such as Next.js, Nuxt and Astro can build pages ahead of time or revalidate them on a timer instead of rendering on every request.

Check the response headers in the DevTools Network panel. A header such as `cf-cache-status: HIT`, `x-cache: HIT` or `age:` above zero means the HTML came from a cache. A `MISS` on every reload means the cache is not storing it, often because of a `Set-Cookie` header or `Cache-Control: private` on the response.

### 2. Make the uncached request faster

When a page cannot be cached, profile the request on the server:

- Slow or repeated database queries. Add indexes and remove queries that run inside loops.
- Calls to other APIs while rendering. Cache their results, or move them to the client after the page loads.
- Plugins, apps or middleware that run on every page view. Remove the ones that do not earn their place.
- An undersized or overloaded server. Check CPU and memory at the time of the run.

A `Server-Timing` response header lets you see the server's own breakdown in the DevTools Network panel, under the Timing tab of the document request.

### 3. Move the server closer, or put a CDN in front

Distance adds time to every request. The lab run happens from a Google data center, and real visitors connect from everywhere. A CDN that terminates connections near the visitor and keeps a warm connection to your origin cuts that part, even before it caches anything.

## How do I fix "Had redirects"?

Every redirect is a full extra request before the HTML. The common chains are `http://` to `https://`, bare domain to `www`, a missing or extra trailing slash, and a geo or language redirect.

1. Test the exact URL you audited with `curl -sIL https://example.com/page` and count the `Location:` headers.
2. Link, canonicalize and list in your sitemap the **final** URL, so visitors and Lighthouse land on it directly.
3. Collapse chains on the server into one hop, and turn on HSTS so returning browsers skip the `http://` redirect.
4. Avoid redirecting mobile visitors to a separate URL.

The [Avoid multiple page redirects](/audits/avoid-multiple-redirects) page covers redirect chains, 301 vs 302 vs 308, and redirect loops in detail.

## How do I fix "No compression applied"?

The HTML went out uncompressed. Turn on Brotli (preferred) or gzip for `text/html` at the server or CDN. Then check the document request in the Network panel: the response should carry `content-encoding: br` or `content-encoding: gzip`. If your origin compresses but the response arrives uncompressed, a proxy in between is stripping it.

## How do I fix it on WordPress, Shopify, or Next.js?

- **WordPress:** slow server response is the usual failure. Use a page cache (your host's cache or a caching plugin), and an edge HTML cache such as Cloudflare APO. Then audit plugins: anything that queries the database on every page view adds to every uncached request. A logged-in Lighthouse run in your own browser bypasses the cache and can look much worse than what visitors get.
- **Shopify:** the platform serves and caches storefront HTML, and you cannot configure the server. Slow responses usually come from heavy Liquid: large loops over collections or products, many sections on one template, and apps that inject server-side code. Trim the template, then re-run. A redirect check failure usually means the audited URL is not the store's primary domain.
- **Next.js:** pages that render on every request (`dynamic` rendering, `getServerSideProps`, uncached `fetch` calls) pay full server time on each hit. Use static generation or revalidation where the content allows, cache data fetches, and deploy close to your data source.

## How do I verify the fix?

1. Re-run Lighthouse. All three checks under Document request latency should pass.
2. Reload a few times in the DevTools Network panel and read the document request's Timing tab. "Waiting for server response" should be well under 600 ms on a cache hit.
3. Check field data. PageSpeed Insights shows Time to First Byte from the Chrome UX Report when your site has enough traffic. The lab run is one request from one place; the field number is your real visitors.

## What mistakes should I avoid?

- **Testing while logged in.** Most page caches skip logged-in users, so your own run hits the slow path every time.
- **Reading one run.** Server time varies run to run. A cache that just expired gives one slow run. Re-run before you change anything.
- **Chasing the 600 ms line.** Passing the check is not the goal. The estimate counts savings against 100 ms, and every millisecond lands on FCP and LCP.
- **Caching personal pages.** Never cache HTML that contains a cart, account details or a CSRF token for anonymous visitors.

## Related audits

- [Avoid multiple page redirects](/audits/avoid-multiple-redirects): redirect chains in depth
- [Enable text compression](/audits/enable-text-compression): compression for CSS, JavaScript and other text files
- [Network dependency tree](/audits/network-dependency-tree): the HTML request starts every critical chain
- [First Contentful Paint](/audits/first-contentful-paint) and [Largest Contentful Paint](/audits/largest-contentful-paint): the metrics this latency is added to

---

Audit your URL at https://lighthouse-md.com.
