Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 10 min read

Lighthouse 84 With a 2.8s LCP: The Missing Points Are in Speed Index

Lighthouse 84 With a 2.8s LCP: The Missing Points Are in Speed Index A mobile Performance score of 84 usually means something is visibly slow. Mine did not look slow. The page had a 2.8-second First Contentful Paint,

Lighthouse 84 With a 2.8s LCP: The Missing Points Are in Speed Index

A mobile Performance score of 84 usually means something is visibly slow. Mine did not look slow.

The page had a 2.8-second First Contentful Paint, a 2.8-second Largest Contentful Paint, 30 milliseconds of Total Blocking Time, and a Cumulative Layout Shift of 0. The desktop score was 99. And yet the mobile score sat at 84.

The number that explained it was not LCP. It was Speed Index: 7.9 seconds.

This is the story of a static HTML page that already had its text in the first response, but still paid for a translation pass and an ad auction before the first screen was complete. The fixes were small. The diagnosis was not.

Measurement boundary: this is a lab result from PageSpeed Insights, not Search Console field data. The run used a simulated Moto G Power, slow 4G (150 ms RTT, about 1.6 Mbps), 1.2Γ— CPU slowdown, and a single homepage URL. The site is a small Express-served static site with vanilla JavaScript and no build pipeline. The Chrome UX Report had no field data for the page, so every number below is synthetic. That matters: a lab score is a diagnostic tool, not a verdict on real users.

The score looked contradictory because I was reading the wrong metric

Treating 84 as an LCP problem is tempting, but LCP was 2.8 secondsβ€”not great, yet not the kind of number that usually produces a 16-point gap. Speed Index measures how quickly the visible page is filled in, not how quickly one element appears. The hero text appeared, then ad slots and a consent surface filled in later. The page was readable early and visually complete very late; Lighthouse scored the second part.

The report also showed:

  • 502 KiB total network payload;
  • 26.4 KiB from the first-party site;
  • about 284 KiB from Google/Doubleclick Ads;
  • about 143 KiB from Google Funding Choices;
  • 205 KiB of unused JavaScript, almost all third-party;
  • 0.9 seconds of main-thread work.

The first-party page was not the problem. The third-party layer was.

Async does not mean free

My first wrong assumption was simple: the AdSense script is loaded with async, so it does not block parsing, so it cannot be the reason the first screen is late.

That is true only in the narrow parser sense. An async script does not stop the HTML parser. It still downloads, executes, opens connections, and competes for the same bandwidth and main thread as everything else. On a 1.6 Mbps link, 420 KiB of third-party code is roughly two seconds of transfer time before TLS and execution are counted.

The report made this concrete: Speed Index was 7.9 seconds, and the third-party breakdown was dominated by ads and consent. The first-party CSS was 6.3 KiB. The first-party translation bundle was 20.1 KiB. The ad stack was more than twenty times larger than the page's own code.

I had read "async" as "outside my critical path." It was outside the parser's path and inside the user's first-screen budget.

The fix was not to remove ads. The site depends on them. The fix was to move the ad request out of the first paint:

  • if the reader interacts (pointerdown, keydown, scroll), load ads immediately;
  • otherwise wait for load, then schedule the ad script in an idle callback with a timeout;
  • do not load ads at all on account, checkout, subscription, and error pages.

That does not make ads free. It makes them late. The reader gets a complete page before the auction starts, and the auction still happens for anyone who stays.

The first-party bug was a 20 KiB translation script

The ad stack explained Speed Index. It did not explain why the hero text itself had a large render delay.

The critical chain in the report was short and ugly:

Resource Transfer size Time in critical chain
/css/site.css 6.3 KiB 160 ms
/js/i18n.js 20.1 KiB 800 ms
email-decode.min.js 1.2 KiB tail of the chain

The translation script sat in the <head> without defer. A synchronous script after a stylesheet must wait for the CSS, and the parser waits for the script before continuing with the body. On a slow link that serialized into a critical path measured at 4,487 ms in the report.

The LCP element was the hero tagline, so this was text, not an image. The report's summary said 2.8 seconds while its breakdown labeled 4,560 ms of render delay; those views can use different traces. I treated the gap as a pointer, not a budget: the text was held back, and the translation script was the only first-party script in front of it.

The script runs an apply() function on DOMContentLoaded. For every element with data-i18n, it did this:

el.textContent = t(key);

Even when the current language was the default English and the new string was byte-for-byte identical to the string already in the HTML, it still wrote to the DOM. That is a text mutation on the largest visible element after the document is ready. Chrome can treat the changed text as a new LCP candidate. A translation pass that changed nothing still reset the clock.

The first fix was therefore not a loading strategy. It was to stop writing when the value is unchanged:

document.querySelectorAll("[data-i18n]").forEach(function (el) {
  var key = el.getAttribute("data-i18n");
  if (!key) return;
  var val = t(key);
  if (el.textContent !== val) {
    el.textContent = val;
    linkify(el);
  }
});

The same rule applies to data-i18n-html, placeholders, titles, and ARIA labels. If the value is already correct, leave the DOM alone. This costs nothing and removes an entire class of "the translation script made LCP worse without changing a word" bugs.

Two ways to load a translation bundle

A translation script changes what the reader sees, so the wrong fix creates a flash of the wrong language.

Strategy First paint Language correctness Cost
Synchronous in <head> Waits for the bundle and CSS Correct for every language Blocks the parser; 20 KiB sits in the critical chain
Preload plus synchronous Same correctness Fetch starts earlier Still blocks execution; may not help if CSS is the dependency
defer only Does not block Default language paints first; non-default language flashes Visible language switch on slow devices
defer plus inline critical strings Does not block Correct first paint for the visible header and hero Duplicate small dictionary; needs a consistency check

For this site, the default HTML is English and the alternate language is Chinese. The first move was preload plus synchronous: keep the correctness of the current design, but let the 20 KiB download start before the stylesheet instead of after it.

<link rel="preload" as="script" href="/js/i18n.js?v=..." />
<link rel="stylesheet" href="/css/site.css?v=..." />
<script src="/js/i18n.js?v=..."></script>

That is low-risk, but it does not remove the script from the critical path; it only shortens the queue. The stronger version is defer plus a tiny inline dictionary for the first screen. The inline script translates only the navigation, hero heading, tagline, and primary buttons, using the language already stored in localStorage; the full dictionary loads deferred.

I did not do that in the first pass. The site's readers include Chinese users, and a first frame in English followed by a switch to Chinese is a visible regression. Preload first, measure, then decide whether the stronger version is worth the duplicated strings.

Two ways to load ads

The ad decision has the same shape, but the cost is revenue instead of language.

Strategy First screen Ad fill Main risk
Async in <head> Competes with CSS, fonts, and first paint Earliest 300–500 KiB and main-thread work land during the first impression
After load, idle callback Clean first paint Delayed by one idle window Some readers leave before an ad is requested
After first interaction only Cleanest Only engaged readers see ads Passive readers may never generate an impression
Remove ads Cleanest None No revenue

The site chose a hybrid: interaction triggers an immediate load; otherwise load plus requestIdleCallback with a 1.5-second timeout. It also removed ads from the account, checkout, subscription, and 404 pages, where they were either low-value or a policy risk.

The implementation is deliberately boring:

(function () {
  var CLIENT = "ca-pub-xxxxxxxxxxxxxxxx";
  var loaded = false;

  function loadAds() {
    if (loaded) return;
    loaded = true;
    var s = document.createElement("script");
    s.async = true;
    s.src =
      "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=" +
      CLIENT;
    s.crossOrigin = "anonymous";
    document.head.appendChild(s);
  }

  ["pointerdown", "keydown", "scroll"].forEach(function (type) {
    window.addEventListener(type, loadAds, { once: true, passive: true });
  });

  if (document.readyState === "complete") {
    loadAds();
  } else {
    window.addEventListener("load", function () {
      if ("requestIdleCallback" in window) {
        requestIdleCallback(loadAds, { timeout: 1500 });
      } else {
        setTimeout(loadAds, 400);
      }
    }, { once: true });
  }
})();

Constraints: this assumes the ad script is the only entry point and that no template calls adsbygoogle.push() before the loader runs. If the page has manual ad slots, the loader has to resolve before those slots initialize, or the slots need their own queue. This also assumes ads are not the main content. If the ad is the content, delaying it is the wrong trade.

What moved, and what did not

The first pass was the idempotent translation write, logo dimensions, and the preload. The second pass was the ad loader.

Run Performance FCP LCP TBT CLS Speed Index
PSI mobile baseline 84 2.8 s 2.8 s 30 ms 0 7.9 s
Local lab after first pass 89 2.8 s 3.1 s 0 ms 0 2.8 s
Local lab after ad loader 99 1.2 s 1.8 s 0 ms 0 1.2–1.5 s

Those runs are not directly comparable. The local runs had no EEA consent banner, and the ad script loaded after the measurement window. The 99 is evidence that the first paint stopped paying for work that could wait; it is not evidence that every real reader gets a 99.

The honest conclusion is narrower than the score: the first-party page was already fast enough; the third-party layer and a no-op translation write were making the first screen pay for work that did not need to happen yet.

When this advice fails

Delaying ads is not universally correct.

  • If ads are the page's main content, a delayed auction produces a visibly empty page. Fix the ad density or the layout instead.
  • If consent is legally required before any ad request, the consent surface must load early enough to collect a choice. Delaying the whole stack is usually compliant because no personalized ad is requested, but this is a legal question, not a performance one.
  • If the default language is not the markup language, defer-only will flash the wrong language. Inline the visible strings or keep the script synchronous.
  • If a 15% revenue drop is unacceptable, load ads immediately after load instead of waiting for idle. Do not put them back in <head> and call it a performance strategy.

The general rule is not "delay third-party scripts." It is: decide which work is allowed to affect the first paint, and make everything else wait without breaking correctness.

A short validation checklist

Run Lighthouse three times on the same URL and configuration, and use the median.

npx lighthouse https://example.com/ \
  --only-categories=performance \
  --form-factor=mobile \
  --throttling-method=simulate \
  --chrome-flags="--headless=new --no-sandbox" \
  --output=json --output-path=./lh.json

Check that the ad script really starts after the load event, not just that the code says it should:

const nav = performance.getEntriesByType("navigation")[0];
performance
  .getEntriesByType("resource")
  .filter((entry) => entry.name.includes("adsbygoogle.js"))
  .forEach((entry) => {
    console.log(entry.startTime > nav.loadEventStart);
  });

Check that the default-language page does not rewrite the LCP text. A small MutationObserver on the hero element should report zero mutations when the page loads in its default language:

let mutations = 0;
new MutationObserver((records) => {
  mutations += records.length;
}).observe(document.querySelector("[data-i18n='home_tagline']"), {
  childList: true,
  characterData: true,
  subtree: true,
});

Check that the change did not break what it touched:

  • switch between both languages and reload;
  • confirm the first frame is in the stored language;
  • confirm ads still fill after the idle window;
  • watch RPM and fill rate for seven days before keeping the delay.

The takeaway

A Lighthouse score of 84 with a 2.8-second LCP is not necessarily an LCP problem. In this case it was a Speed Index problem caused by a third-party stack, plus an LCP problem caused by a translation script that rewrote text it did not need to touch.

The two fixes were almost embarrassingly small: do not write the same string twice, and do not start an ad auction before the reader can see the page. The hard part was believing that a 20 KiB first-party script and a 420 KiB third-party layer were more important than the metric that was already green enough to ignore.

The score was not lying. It was charging the first paint for work that could have waited. The longer rebuild behind this site is documented at wuhuajin.com.

Originally published on wuhuajin.com.

πŸ“° 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.