Dev.to WebDev πŸ›  Dev πŸ‘ 2 πŸ“– 5 min read

The largest thing on 23 of our 38 pages is a different element at 1280px than at 390px, and our layout shift is exactly 0 on all 76 loads

When people talk about Largest Contentful Paint they usually mean a hero image. Notifio's website has one 550-byte image, which I wrote up in an earlier post about our one image file, so on this site the LCP element is a

When people talk about Largest Contentful Paint they usually mean a hero image. Notifio's website has one 550-byte image, which I wrote up in an earlier post about our one image file, so on this site the LCP element is always text. That leaves a question I had never asked: which text? The browser picks the element with the biggest painted area inside the viewport, and I had assumed, without ever checking, that it was the h1.

A sibling site of mine has an LCP post for its 76 pages. That one is about timing. This one is about identity, and about what changes when the window changes, which the 76-page post did not vary.

The probe

Two observers, installed before any page script runs so nothing in the first hundred milliseconds is missed:

await page.addInitScript(`(() => {
  window.__lcp = []; window.__cls = 0;
  new PerformanceObserver(l => { for (const e of l.getEntries()) {
    const el = e.element;
    window.__lcp.push({ tag: el && el.tagName, size: e.size,
      txt: el && (el.textContent || '').trim().slice(0, 50) });
  } }).observe({ type: 'largest-contentful-paint', buffered: true });
  new PerformanceObserver(l => { for (const e of l.getEntries())
    if (!e.hadRecentInput) window.__cls += e.value;
  }).observe({ type: 'layout-shift', buffered: true });
})()`);

Then every URL in the sitemap (38 of them), at 1280x800 and again at 390x844, waiting 2.5 seconds after load before reading the last LCP entry. I use Chromium from the app's own Playwright install, headless, one browser context per width. I did not disable the HTTP cache, so the fonts were warm for every page after the first.

I am deliberately not reporting milliseconds. I ran this on a laptop with a load average of 8 and other things open, and the timings are not worth quoting. Element identity, element counts and shift counts are immune to that.

What the largest element is

At 1280 pixels wide:

P      24 pages
H1     12 pages
DIV     1 page    (/help)
LI      1 page    (/privacy)

24 of 38 are a paragraph. Not a heading, not a card, not a button. Within those, the same utility string wins 16 times: text-[15px] leading-relaxed text-[#a3a3a3], which is our standard grey body paragraph. A further 5 are the same string in a lighter grey (#d4d4d4), which are the five comparison pages. The 12 pages where the h1 wins use the 34px heading class on nine of them and the 40px class on the other three: the home page, pricing and download.

Every page reports exactly one LCP entry. Normally the entry is replaced as bigger things paint, but nothing on this site paints late enough to take over: 0 of 76 loads reported a second candidate.

The same page, narrower

Then the same measurement at 390 pixels wide. The mix becomes:

P      18 pages
H1     17 pages
LI      2 pages
DIV     1 page

That is a different distribution, but the totals hide the more interesting number. On 23 of 38 pages the LCP element is not the same element at the two widths. The biggest group is the 15 per-site pages under /alerts. Take the Kamernet page: at 1280 the winner is the paragraph beginning "Kamernet lets you save a search", at 118,192 square pixels, the largest LCP area on the whole site. At 390 the winner is the h1. The same happens on Pararius, Funda, Rightmove, Zoopla, SpareRoom, Idealista, ImmobilienScout24, WG-Gesucht, HousingAnywhere and Spotahome: 11 of the 15 swap a paragraph for the heading.

I measured why, with getBoundingClientRect and the part of each box that sits inside the viewport. On that page at 1280x800:

h1         42px type   720 x 94    starts at y=209   67,725 px2 in view
paragraph  15px type   720 x 171   starts at y=605   122,850 px2 in view

The heading is short. The paragraph is a tall block that begins at y=605, which is still inside an 800 pixel window, so all 171 pixels of it count. At 390x844 the layout is:

h1         34px type   342 x 114   starts at y=209   39,068 px2 in view
paragraph  15px type   342 x 366   starts at y=788   19,232 px2 in view

The paragraph is now 366 pixels tall because the column is narrow, and it starts at y=788, so only the top 56 pixels are inside an 844 pixel screen. The heading, which was already on screen, wins. The winner changes because a paragraph slid under the fold, not because anything about either element changed.

Nothing about this is a bug. It is what "largest area inside the viewport wins" means, and I had never connected it to a real page.

What it means for what we edit

The reason this matters is editorial. If you believe the LCP element is the heading, you tune the heading: shorter text, a font that is already loaded, no animation on it. On this site that tunes the winner on 12 pages at desktop width. On the other 26 the element being timed is a paragraph, a list item or a block in the body, and the first paragraph of a page is something I edit freely and without thinking about performance at all.

A few specific numbers from the data:

  • The largest LCP areas are on the per-site pages: Kamernet at 118,192 square pixels, Facebook Marketplace at 103,194 and ImmobilienScout24 at 101,246, all at 1280 width.
  • The three smallest are /help at 36,928 (a div), /privacy at 37,044 (a list item) and /terms at 42,228 (a paragraph).
  • The home page's winner is its h1 at both widths, at 84,560 square pixels on the desktop run.
  • An image above the fold would out-area any of these text blocks on all 38 pages at once. The site has none, so none of this changes until it does.

Layout shift: 0, 76 times

I also summed layout-shift entries that had no recent input. All 76 loads, 38 pages at two widths, returned 0 shifts and a CLS of exactly 0. Not 0.001. Zero.

The caveat is honest and specific. This is unthrottled, with a warm cache after the first page, which means the self-hosted fonts were already in memory. In a different post I measured the fonts on all 38 pages, loaded and blocked, and on a throttled connection the late-arriving fonts did move text a little. So 0 here is the fast path being fast, not proof that nothing can move.

What I would check on your site

One question and one script. The question: is the element you are optimising actually the element Chromium is timing? The script is the twelve lines above, with buffered: true so it catches entries from before the observer existed, run at your narrowest and widest breakpoints rather than only the one on your monitor.

If the answer differs between the two widths on more than a handful of pages, you have a metric that depends on which device your reader holds, and an h1 rewrite will move half of them and not the other half.

The pages used here are all live, so you can repeat it: start from the sitemap, or just open /alerts/kamernet at two window widths and watch which block Chrome's Performance panel marks as LCP.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.