completefrontend

Predict the outputMedium

Which element does the browser report as the LCP?

The tea shop's product page has a heading, a short paragraph, and a picture of the tea, which the server is slow to send. Its script watches largest-contentful-paint entries with a PerformanceObserver, buffered: true, and logs them a second after the load event. What does it log?

index.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Mint tea | Leaf and Kettle</title>
  <style>
    body { margin: 0; padding: 16px; font-family: system-ui, sans-serif; }
    h1 { margin: 0 0 8px; font-size: 32px; }
    #hero { display: block; max-width: 100%; height: auto; }
  </style>
</head>
<body>
  <h1>This week: mint tea</h1>
  <p>Picked this week.</p>
  <img id="hero" src="mint.svg" alt="A glass of mint tea" width="300" height="200">
  <script src="lcp.js"></script>
</body>
</html>
lcp.js
// Every largest-contentful-paint entry, including the ones from before this script ran.
const candidates = [];
new PerformanceObserver((list) => {
  candidates.push(...list.getEntries());
}).observe({ type: "largest-contentful-paint", buffered: true });
 
// An element as its tag, and its id when it has one: "img#hero".
const describe = (element) => (element ? element.tagName.toLowerCase() + (element.id ? "#" + element.id : "") : "(removed)");
 
// A second after the load event, log what the browser reported.
addEventListener("load", () => {
  setTimeout(() => {
    console.log("Candidates: " + candidates.length);
    candidates.forEach((entry, index) => console.log("Candidate " + (index + 1) + ": " + describe(entry.element)));
    console.log("LCP element: " + describe(candidates.at(-1)?.element));
    document.body.dataset.logged = "true";
  }, 1000);
});
mint.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 200" width="300" height="200">
  <rect width="300" height="200" fill="#f3efe4"/>
  <!-- The table -->
  <rect y="160" width="300" height="40" fill="#c9a77c"/>
  <path d="M0 168h300M0 180h300M0 192h300" stroke="#b48f62" stroke-width="2"/>
  <!-- The glass, and the tea in it -->
  <path d="M105 50h90l-12 108a8 8 0 0 1-8 7h-50a8 8 0 0 1-8-7z" fill="#e8f1e2" stroke="#8aa57c" stroke-width="3"/>
  <path d="M111 78h78l-8 76a6 6 0 0 1-6 5h-50a6 6 0 0 1-6-5z" fill="#b5652a" opacity=".85"/>
  <g fill="#f6d9b8" opacity=".7">
    <circle cx="130" cy="100" r="3"/>
    <circle cx="160" cy="120" r="2.5"/>
    <circle cx="145" cy="140" r="2"/>
    <circle cx="172" cy="96" r="2"/>
    <circle cx="124" cy="128" r="1.5"/>
  </g>
  <!-- Mint leaves -->
  <g fill="#3f8f3a" stroke="#2c6a28" stroke-width="1.5">
    <path d="M150 52c-14-22-6-38 8-44 6 16 4 32-8 44z"/>
    <path d="M152 54c18-14 34-12 42-2-14 10-28 10-42 2z"/>
    <path d="M148 56c-20-6-30 2-34 14 16 2 28-2 34-14z"/>
  </g>
  <path d="M150 52l6-38M152 54l34-5M148 56l-28 9" stroke="#2c6a28" stroke-width="1.2" fill="none"/>
  <!-- Steam -->
  <g fill="none" stroke="#bdb6a6" stroke-width="3" stroke-linecap="round">
    <path d="M128 42c-6-8 6-14 0-22"/>
    <path d="M174 42c-6-8 6-14 0-22"/>
  </g>
  <text x="150" y="188" text-anchor="middle" font-family="sans-serif" font-size="14" fill="#5b4630">Mint tea</text>
</svg>

Chrome loads these files from a server on the same computer, index.html at /, in a fresh profile with an empty cache, on a phone's screen (412 by 823 CSS pixels), with no network or CPU slowdown. The server holds back mint.svg for 800 ms before it answers.

  1. You open the page in Chrome and don't touch it.
  2. The picture arrives 800 ms after the browser asks for it.
  3. A second after the load event, the script logs what it saw.

The answer

Work out what Chrome does with the page: every line it logs, in order, and how it treats each file. Then check.

Checking your sign-in…