One header Payload adds to every route doubled my mobile LCP
Moving this site from static Astro to Payload CMS took Lighthouse mobile LCP from 1.08 s to 2.17 s. The cause was one response header the framework adds to every route, and it cost every first Chromium visit a second navigation.
In November I moved this site from a static Astro build to Payload CMS on Next.js 16. Same pages, same CSS. On Lighthouse mobile, the static build had an LCP of 1.08 s and the first Payload build had 2.17 s.
A server-rendered page is expected to be a bit slower than a file read from disk. Twice as slow on a site this small is not what server rendering costs, though. So before touching caching or the database, I looked at what the response actually carried.
Three headers I did not write
Every route on the new site, including the home page, a product page and a blog post, answered with these three headers:
Accept-CH: Sec-CH-Prefers-Color-Scheme
Vary: Sec-CH-Prefers-Color-Scheme
Critical-CH: Sec-CH-Prefers-Color-SchemeNone of them came from my code. Payload's Next.js wrapper `withPayload` (`@payloadcms/next`, version 3.93.0 here) appends a `headers()` rule with `source: '/:path*'`, so the headers land on every path the app serves. They exist for a good reason: the Payload admin panel reads `Sec-CH-Prefers-Color-Scheme` to render the dark or light theme on the server without a flash. The admin is the only reader, but the rule covers the whole host.
`Accept-CH` on its own is harmless. It asks the browser to send the hint on later requests. `Critical-CH` is the expensive one. It tells a Chromium browser that this response depends on the hint, so if the browser supports the hint and did not send it, it should throw the response away and repeat the request with the hint attached. On a first visit the browser has never been asked for the hint, so it never sent it. Every first navigation to the site therefore became two navigations: the first response was downloaded, then discarded and requested again.
Lighthouse runs on a clean profile, so it pays that cost on every run. Under its mobile throttling, the second round trip for the document came to about a second, which was the whole gap between 1.08 s and 2.17 s. Safari and Firefox do not implement client hints, so their visitors never paid it. Returning Chromium visitors had already been asked for the hint, so they did not pay it either. It was a first-visit, Chromium-only cost, which is exactly the visit a portfolio site gets most.
The fix, twice
The quick fix was at the reverse proxy. Caddy can remove response headers, so two lines in the site block took them out:
header {
-Critical-CH
-Accept-CH
}With those headers gone, Lighthouse mobile LCP dropped to 1.15 s, within 70 ms of the static build. The proxy strip has a cost, though. It applies to every path, `/admin` included, so the admin no longer receives the hint and its theme falls back to the default colour scheme.
The proper fix is in the app: keep the hints, but only where the admin reads them. `withPayload` returns an ordinary Next config, so I wrap it and move the hint headers from `/:path*` to the admin route, leaving every other header where it was:
const clientHintHeader = ({ key, value }: { key: string; value: string }) =>
['accept-ch', 'critical-ch'].includes(key.toLowerCase()) ||
(key.toLowerCase() === 'vary' && value.toLowerCase().includes('sec-ch-prefers-color-scheme'))
const scopeClientHintsToAdmin = (config: NextConfig): NextConfig => ({
...config,
headers: async () =>
((await config.headers?.()) ?? []).flatMap((rule) => {
const hints = rule.headers.filter(clientHintHeader)
const rest = rule.headers.filter((h) => !clientHintHeader(h))
if (hints.length === 0 || rule.source === ADMIN_SOURCE) return [rule]
return [
...(rest.length ? [{ ...rule, headers: rest }] : []),
{ ...rule, source: ADMIN_SOURCE, headers: hints },
]
}),
})
export default scopeClientHintsToAdmin(withPayload(nextConfig))`ADMIN_SOURCE` is `'/admin/:path*'`. A unit test loads the final config's `headers()` and asserts that no rule matching `/`, `/products/:slug` or `/writing/:slug` carries `Critical-CH` or `Accept-CH`, and that the admin rule still does. Remove the wrapper and the test goes red. That matters because this regression never reaches an error log. The page renders and every status is 200. The only symptom is a number in a performance report.
I kept the Caddy lines as well. After both changes the home page, the OxSay page and the writing index each score 100 on Lighthouse mobile, with an LCP between 1.0 and 1.18 s.
Upstream
This is a known issue. payloadcms/payload#17906, opened in August against 3.88, proposes scoping the injection to the admin route or making it an option. It was still open when I checked, and the same rule ships in 3.93.0. Until it lands, every Payload site on Next.js sends `Critical-CH` from its marketing pages unless someone removes it.
The takeaway
If a Payload site or any Next.js app is slower on its first mobile load than it should be, run one command before profiling anything:
curl -sI https://your-site/ | grep -i -E 'critical-ch|accept-ch'If `Critical-CH` names a hint your public pages never read, every first Chromium visit is downloading the page twice. Scope it to the route that reads it, and leave a test behind. Nothing else will tell you when it comes back.