A real mechanism is not a faster page
Six web-performance changes with real mechanisms that did not make LCP faster, one rejected wrongly, the three that worked, and an A/B protocol that can say no.
By Nelson D’Souza · · 16 min read
- Performance
- Measurement
- Next.js
In this note
- Profile, remove, profile again
- Hypothesis 1: prioritise the LCP image
- Hypothesis 2: match the fallback font's size
- Hypothesis 3: stop inlining the CSS
- Hypothesis 4: merge the chunks
- Hypothesis 5: replace the tag manager
- Hypothesis 6: defer the auth dialog
- What actually worked
- Five instruments, confidently wrong
- An A/B that is allowed to come back null
- A coda from this site
Theo Scriptura is a Bible-study product, and much of its traffic arrives from search, signed out, on a phone. For a month I worked on its mobile load time. The metric was Largest Contentful Paint (LCP: the moment the biggest thing in the first screen finishes painting), measured on a Pixel 7 profile with 4x CPU slowdown, 1.6 Mbps down and a 150 ms round trip. A route budget gate in CI, a ratchet on each route’s bytes, keeps a gain once it’s won.
Six of the changes I tried came with a correct account of why the page was slow, and none of them made it faster. One made LCP worse, four changed nothing because the binding constraint was elsewhere, and one I rejected on an incomplete comparison. The three that worked each took work away instead of reordering it. Below are the six, the three, and the A/B protocol that let the measurements overrule a mechanism I believed.
Profile, remove, profile again#
The standard loop is to profile, remove something wasteful, profile again, and ship if the number went down. It leaves four things unsaid: which number, measured how, compared with what, and what result would have made you stop. For a large fix none of that matters. For a few hundred milliseconds on a throttled phone, run-to-run noise is about the same size, and a mechanism you already believe fills the gap.
Hypothesis 1: prioritise the LCP image#
The /blog index’s LCP image took 1,525 ms to download 60 KB on a link that should move it in about 300 ms. Its time in the queue was 1 ms, so it was not waiting for a turn. It was downloading slowly because two below-the-fold card images, marked loading="lazy", started while it was still in flight. Chrome starts a lazy image while it’s still well below the viewport, and on a narrow phone the next two cards qualified.
The standard fix is fetchPriority="high" on the featured card and "low" on the rest. Deployed and measured over four runs, the LCP image started earlier (556 ms to 412 ms) and its download got slower, 1,525 ms to 1,771 ms, in all four runs. The low-priority cards still started at 789 ms. LCP itself read better, but not by more than the variance of measuring a live site over the internet; the slower download was consistent. I reverted it.
The arithmetic says it could never have worked. The LCP window needed three images, 183 KB in total. At 1.6 Mbps, about 200 KB a second, that is roughly 915 ms of transfer that has to happen in some order, and a priority hint can only change the order. On a saturated link, the image’s earlier start bought it nothing, because its bytes still shared the pipe with the cards.
The local A/B of the same change came back identical, 1,456 ms in both arms. That doesn’t mean the change did nothing. A server on localhost has no bandwidth contention to redistribute, so it can’t see this effect in either direction.
Hypothesis 2: match the fallback font’s size#
/ask painted its first content at 620 ms and reported LCP at 2,920 ms, with 111 KB transferred and almost no layout shift (CLS 0.0013). The page looked done long before the metric agreed.
The LCP candidate list explained it. The browser reports every new largest paint, and this page had two entries for the same heading:
t= 640ms size= 19028 rect=380x75 H1 (fallback serif)
t= 2924ms size= 22464 rect=380x75 H1 (Playfair Display)Same element, same bounding box, larger size. LCP measures text by the area of the text’s own rectangles, not the element’s box. When the display font arrived and replaced the fallback, its wider glyphs filled more of the same box. Nothing moved, so layout shift stayed near zero, but the browser saw a new, larger candidate 2.3 seconds in.
- Server to Browser: “HTML and CSS”
- Browser, internally: “paint in fallback serif”
- Browser to LCP observer: “candidate 1: 640 ms”
- Server replies to Browser: “display font arrives”
- Browser, internally: “swap: wider glyphs”
- Browser to LCP observer: “candidate 2: 2,924 ms”
- LCP observer replies to Browser: “LCP reported ≈ 2.9 s”
Before changing anything, I ran a third arm that blocked the font files outright. /ask went to 756 ms. That confirmed the mechanism and set a floor: any real fix had to get near 756.
The first fix was the elegant one. The CSS named Georgia as the fallback, and next/font generates a metric-matched fallback family for exactly this case, scaled with size-adjust: 111.26% so the fallback takes up the same space as the real font. The arithmetic was consistent with the symptom: an 11% linear difference, and an observed 18% growth in area.
It changed nothing: 2,940 ms to 2,920 ms, inside noise. The generated fallback is local("Times New Roman"), and a Linux lab machine doesn’t have Times New Roman, so that face never loaded. Both arms fell through to the same system serif, Liberation Serif, which the machine’s font matcher substitutes for Georgia and Times New Roman alike. size-adjust never applied in either arm. Android has neither face either.
A local() fallback only works where the operating system ships the font it names. This fix couldn’t be tested on the machine I was testing on, and it does nothing for the phones I was trying to help. I kept it, because it brings the first view closer to the real font on iOS and Windows, but recorded it as not the performance fix. The measurements that followed were taken with it already in place, so it can’t take credit for them later.
Hypothesis 3: stop inlining the CSS#
A blog article served 855 KB of HTML for 53 KB of actual markup. The inline <style> block was 42% of the document and the React Server Components payload was 50%, and the payload contained a second, escaped copy of the whole stylesheet so client-side navigations could apply it. Even after compression at the edge, the duplicate cost about 20 KB per page view. That is a real mechanism, and the standard move is to turn off Next’s experimental.inlineCss and link the stylesheet instead.
Linked, the document went from 855,317 bytes to 131,343, 85% smaller. LCP got worse on six of seven routes, by up to 888 ms.
The shape of the losing arm says why. With the CSS linked, FCP and LCP collapsed to the same number on every route, and seven routes with very different content all landed between 1,356 and 1,716 ms. Inline, the same routes spread from 624 to 1,460 ms. Unrelated pages converging on one time meant a floor, and here the floor was a render-blocking stylesheet: nothing paints until it lands, so shrinking the document cannot help.
What made the re-test cheap was the original decision, five weeks earlier, recorded with its metric: inline won on FCP by 153 ms, while LCP preferred linking by 168 ms. LCP had since become the binding metric, which is what justified running it again. The note now records a condition instead of a verdict: revisit only if Next stops writing the stylesheet into the payload while still inlining it.
Hypothesis 4: merge the chunks#
This one started with a measurement I still like. Two experiments disagreed. Removing 169 KB of card images from /blog’s LCP window changed nothing (1,796 to 1,820 ms). Removing 255 KB of JavaScript from an article’s window cut LCP from 1,640 to 916 ms. Similar bytes, opposite results.
Blocking subsets of the JavaScript on production, median of four runs, settled it:
| Arm | Bytes blocked | Requests | Median LCP |
|---|---|---|---|
| Baseline | none | none | 1,688 ms |
| Framework chunks | 126,796 | 2 | 1,552 ms (−136) |
| App chunks | 132,173 | 25 | 1,004 ms (−684) |
Almost the same bytes. Twenty-five requests cost five times as much as two. That works out to about 24 ms of LCP per additional concurrent request: (684 − 136) / 23. HTTP/2 multiplexes every request over one connection, and if the server shares it roughly equally, the LCP image gets a quarter of the pipe with four requests in flight and a twenty-eighth with twenty-eight. That equal-share picture is a model that fits two data points, not a reading of the server’s scheduler, and per-request overhead would push in the same direction. Either way, the count was what cost.
- In the LCP window contains Document and fonts, Framework JS, 2 streams, App JS, 25 streams, LCP image.
- Document and fonts to One connection, ≈200 KB/s
- Framework JS, 2 streams to One connection, ≈200 KB/s: “−136 ms”
- App JS, 25 streams to One connection, ≈200 KB/s: “−684 ms”
- LCP image to One connection, ≈200 KB/s: “≈1/28 share”
If request count is the lever, merge the chunks. One minSize: 60_000 in the client splitChunks config took an article from 29 chunk URLs to 19. A local A/B measured 864 ms against 864 ms.
I dismissed that result. Localhost read 864 ms where production read 1,688 ms, and I had recently learned, from the priority hints, that a local server hides contention. So I decided the lab could not see a production-only win and opened a PR to measure on a preview deployment.
The route budget gate rejected the PR on every route, and its numbers supplied the mechanism. minSize merges modules into shared chunks regardless of which route needs them, so a route that wanted a small chunk now pulled a 606.6 KB one full of other routes’ code. For the article: +47.7 KB of first-load JavaScript, about 228 ms at 200 KB a second, against −10 streams, about 240 ms. Net, roughly zero. The local null was exactly right. There was nothing to see anywhere.
The instrument was right and my reading of it was wrong. This is the failure the protocol at the end exists to stop: a mechanism with a real basis overruling a null result. I had confirmed that throttling applied on localhost, which ruled out the one reason that could have justified setting the null aside. The question that would have settled it sooner was whether the change could lose as well as fail to win.
Hypothesis 5: replace the tag manager#
The tag manager script was the largest single script on every route: 357 KB decoded, 120 KB over the wire, to load a container holding exactly one tag, the analytics tag. Loading analytics directly looked like an obvious saving.
I priced the replacement before removing anything. Loaded directly, the analytics library is 529 KB decoded and 176 KB over the wire, against the tag manager’s 357 KB and 120 KB. Decoded, the direct load is 172 KB more (529 − 357). I kept the tag manager and filed it as a regression avoided.
That verdict was wrong, and the error is a standard one in cost accounting: pricing an incumbent by the requests your own HTML shows. The container’s one tag loads that same analytics library. A cold load of /blog fetches both, the tag manager and then the analytics library, which the container requests itself.
| What I counted | Scripts it loads | Decoded |
|---|---|---|
| The tag manager, as I priced it | the tag manager | 357 KB |
The tag manager, as a cold load of /blog fetches it | the tag manager, then the analytics library its one tag requests | 357 + 543 = 900 KB |
| Analytics loaded directly | the analytics library | 529 KB |
So the comparison was one script against two, and going direct would remove the very script I’d set out to remove. Pricing the replacement was the right instinct; I priced it against half of what the incumbent loads. The tag-manager accounting mistake has since been fixed.
Both scripts still load, and together they are larger than anything this post removed. On LCP they cost less than their size suggests, because the tag manager is loaded with Next’s lazyOnload strategy, during browser idle time after the page’s other resources, so it doesn’t contend for the connection the way the app’s own chunks do. A reader on mobile data still downloads all of it, and nothing in this post reduced that.
Hypothesis 6: defer the auth dialog#
A blog article fetched a 175.8 KB chunk containing the whole database client, with auth, realtime and storage, on a prerendered page that signed-out readers cannot use. The import chain looked simple: /ask imported an auth dialog eagerly, the dialog imported the auth client, and the auth client pulled in the SDK.
Round one lazy-imported the auth functions at their call sites in six files. Round two wrapped the dialog in next/dynamic in six more. Both rounds left every route byte-identical. The decisive check took seconds: the SDK chunk had the same filename hash before and after both rounds. Webpack derives a chunk’s filename hash from what’s in it, so an unchanged hash meant the chunk itself hadn’t changed, and with every route byte-identical, nothing about what loaded had changed either.
The auth client had about a dozen other eager importers: the login, sign-up and password-reset forms and their routes. Removing two paths into a module reached by a dozen leaves it exactly where it was. Both rounds were reverted, twelve files of dynamic imports for zero measured bytes.
- Count a heavy module's eager importers to One owner and a trigger?
- One owner and a trigger? to Defer it (toaster: −31.9 KB a route): “yes”
- One owner and a trigger? to It's a floor (popper: ≈30 importers): “no, many”
- It's a floor (popper: ≈30 importers) to The ratchet holds it
- Defer it (toaster: −31.9 KB a route) to Chunk hash changed?
- Chunk hash changed? to Ship: “yes, and bytes fell”
- Chunk hash changed? to Revert and record: “no”
The shape that does work showed up later. The toast notification library had one <Toaster> in the root layout; deferring it removed 31.9 KB from all seven budgeted routes. A verse-preview sheet had one owner behind a tap; deferring it removed 47.6 KB from articles. The positioning library behind tooltips, dropdowns and selects is the opposite case: 28.6 KB on 127 of 373 routes, including the 404 page, with about thirty importers across four components. That one is a floor, and the ratchet holds it there.
What actually worked#
Three changes, and each one took work away instead of reordering it. The first two moved LCP; the third removed bytes every reader who scrolled was paying for.
display: optional on the display font. With optional, the browser gives the font a very short window to arrive and never swaps after it; on a cold load it keeps the fallback, so there is no swap and no second candidate. /ask went from 2,920 ms to 624 ms, at or below the 756 ms fonts-blocked floor, which says the font was essentially the whole cause on that route. CLS went to 0 on every route. In production /ask measured 736 ms. The cost is a brand decision, stated as one in the code: a first-time reader on a slow connection does not see the display face on that first page view. The file still downloads and is cached for the next one.
Image quality 65 on blog photographs. This is the “fewer bytes” lever the priority hints pointed at, applied to the LCP image itself. I chose the value by measurement: bytes as the browser receives them, against the difference from quality 75 computed at the size the reader actually sees.
| Quality | Bytes (w=1080) | PSNR as displayed on a phone |
|---|---|---|
| 75 | 59.6 KB | reference |
| 65 | 50.8 KB | 40.6 dB |
| 60 | 47.4 KB | 39.9 dB |
A phone at a device pixel ratio of 2.625 displays a 1,080-pixel image at 378 CSS pixels, and that downscale hides compression artefacts. Sixty-five is the lowest value that still clears the 40 dB “visually lossless” convention as displayed. Measured per device class, it does not clear it everywhere: on a DPR 1 desktop, with no downscale to hide anything, it is 36.7 dB. I accepted that deliberately, because desktop readers already download the small candidate and are not short of bandwidth.
In production, five runs against five, articles went from 1,932 ms to 1,612 ms and the index from 2,544 ms to 2,248 ms. Routes the change didn’t touch drifted by up to 196 ms over the same runs, so part of that is the network. The mechanism is what makes the rest credible: the article’s LCP image went from 48.0 KB to 40.5 KB and its download from 1,544 ms to 1,306 ms. That is what separates it from the reverted priority hints. The bytes moved, and the download moved with them, in the predicted direction. It also squares with hypothesis 4. If the image gets a roughly fixed share of the pipe, its own bytes set how long it takes, which would explain why shrinking the image helped where removing three competing card images hadn’t.
One trap is that Next 16 rejects any quality not listed in images.qualities, with an HTTP 400 and a 44-byte body. You get a broken image. A test now asserts that every quality a component passes is in the allowed list.
prefetch={false} on links I had added. A cold load of one article fetched 45 JavaScript chunks, 1,122.3 KB decoded. Of that, 350.4 KB arrived after the first second and was never used. A new blog header had put four Next <Link>s to app routes on every article, and the App Router prefetches a link’s route when the link scrolls into view. Those routes pulled in the 175.8 KB database client from hypothesis 6, which explains that one from the other side: the blog was fetching the chunk through prefetch, so the route that had to stop asking for it was the blog, not /ask. With prefetch off on those links, and one more in a sign-up capture, the page fetched 29 chunks and 771.9 KB, and the database client not at all.
The cost is about 1,258 ms to route change, on an unthrottled connection, when a reader clicks a header link, against near-instant before. For a content page read mostly by signed-out visitors, a certain 350 KB on mobile data was the worse deal.
Five instruments, confidently wrong#
Over the month, five measurement instruments gave me confidently wrong output. The one that would have cost the most was an A/B that blocked below-the-fold images and appeared to take /blog LCP from 2,412 ms to 816 ms. The blocking rule let “the first image request” through, and that did not reliably identify the LCP image. In some runs it blocked the LCP image itself, and LCP fell back to a text node that paints early. The tell was in the ordering. Blocking more looked faster than blocking less, which a working instrument can’t produce.
The fix is one line of bookkeeping in every arm:
// Record the LCP entry's own element in every arm.
// Arms that do not share an LCP element are not comparable.
elements.add(entry.url ?? '(text)');The others were quieter. My own browser profile was signed in, so production pages restored my session on every load and pulled the 175.8 KB auth client at 622 ms, which read for two days as prefetch waste on a page where signed-out readers never load it. The same long-lived profile reported a transfer size of 0 for every chunk because they were all in its HTTP cache. A stale build directory served HTML pointing at a chunk that returned 404, hydration broke, chunk loading stopped at 16 instead of 44, and it looked like a spectacular improvement. And the budget gate itself reads the build manifest, so it sees neither third-party scripts nor prefetched routes: it measured an article at 392 KB while a browser decoded 1,204 KB.
None of these would have been caught by reading the code. Each was caught by a case with a known answer: a control that had to fail, a number that was too good, two readings that could not both be true.
An A/B that is allowed to come back null#
The mechanisms behind the failed fixes were real. The duplicated CSS was real waste, and the chunk count really did cost about 24 ms a request. The changes still didn’t make the page faster, because what bound LCP was somewhere else: a render-blocking floor, a shared pipe, bytes that came back through another door. Telling those apart from the fixes that work took a measurement that was allowed to come back null.
- Hypothesis, decision rule, control arm to Known-bad case fails?
- Known-bad case fails? to Fix the harness: “no”
- Fix the harness to Known-bad case fails?
- Known-bad case fails? to Same LCP element?: “yes”
- Same LCP element? to Fix the harness: “not comparable”
- Same LCP element? to Repeat runs, cold, signed out: “yes”
- Repeat runs, cold, signed out to Apply the rule
- Apply the rule to Ship: “it moved”
- Apply the rule to Revert and record: “null or worse”
The number of runs matters more than it looks. A first pass at blocking fonts on /blog, three runs per arm, suggested a 464 ms win. Five runs per arm on that route gave 1,800 ms against 1,648 ms, about 152 ms, with spreads that barely separated. A three-run median with a 276 ms spread cannot resolve a 150 ms effect, and quoting the first number would have tripled the prize.
Writing the decision rule first is what made closing the chunk-merging PR quick rather than a negotiation with myself. I had stated what would count as a win before the result arrived, so when the budget gate and the local null agreed, there was nothing left to argue about.
A coda from this site#
The same class showed up on the site you are reading. A Lighthouse mobile run put /writing at an LCP of 4.8 s, and the LCP element was the first list entry, with 1,083 ms of render delay. It was marked for a scroll-reveal animation, so it stayed invisible until a client script hydrated and revealed it. If hydration failed, that content would never show at all. The change was to let the first-screen entries animate on CSS alone and keep the script-driven reveal below the fold. The next Lighthouse runs put /writing at 3.3 s (and these synthetic Pixel 7 gains still await real-user CrUX or RUM confirmation).
The same review found all four fonts preloaded on every route, 242 KB. An A/B that blocked two of the preloads was inconclusive, so the review counted it as a byte cost and left the LCP effect unproven. When I later dropped the preloads for the handwriting and mono fonts, /writing LCP improved, but home FCP went from 1.36 s to 1.81 s over three Lighthouse runs a side, because the hero’s hand-lettered line uses the handwriting font. A three-run check is rougher than the five-run protocol above, with no spread reported; I accepted it only because the hero handwriting-font preload mechanism was direct and reverting cost nothing. A preload moves bytes earlier, and it competes with whatever else is on the critical path. That preload went back in. It was the cheapest revert of the month, which is a low bar.
Built in: Theo Scriptura