Open data & tools

Lighthouse and Lighthouse CI on ad-heavy pages: setup, budgets and measuring third-party impact

Last updated Published By the editorial team6 min4 sources

Key takeaways

  • Lighthouse is Google's open-source lab auditing tool (Apache-2.0); version 13.6.0 is current on npm and requires Node 22 or later.
  • Lighthouse CI (@lhci/cli 0.16.1) runs Lighthouse several times per URL, three by default, and can fail a build when assertions on scores, metrics or resource budgets are not met.
  • In Lighthouse 13 the performance score weights Total Blocking Time 30%, Largest Contentful Paint 25%, Cumulative Layout Shift 25%, First Contentful Paint 10% and Speed Index 10%.
  • The blockedUrlPatterns setting lets you run the same page with ad requests blocked, which isolates how much of the lab result comes from ad code.
  • Lighthouse is a lab test on one simulated device; field data from CrUX or your own real-user monitoring decides how real visitors experience ads.
An analog stopwatch
Image: Analog Stop Watch,Jeremyida002,CC BY-SA 4.0,via Wikimedia Commons.

Lighthouse is Google’s open-source lab auditing tool, and Lighthouse CI runs it automatically on every build with pass/fail budgets. On ad-supported pages, the useful setup runs each page twice, once normally and once with ad requests blocked, so you can see how much of a slow Largest Contentful Paint or high Total Blocking Time comes from ads and how much from your own code.

What Lighthouse can and cannot tell you about ads

Lighthouse loads one page, in one Chrome instance, with simulated throttling, and reports lab metrics. On an ad page that means:

  • It sees one auction outcome. The next run may receive a heavier or lighter creative.
  • It sees no consent state unless you script one, and no user interactions, so Interaction to Next Paint is not part of the score.
  • It is good at attribution. It lists which third parties transferred how many bytes and used how much main-thread time.

Field data answers “do real visitors suffer?” (see CrUX for publishers and real-user Core Web Vitals). Lighthouse answers “what changed, and whose code is it?”.

How the performance score is built in Lighthouse 13

From the default config in the Lighthouse repository:

Metric Weight
Total Blocking Time (TBT) 30
Largest Contentful Paint (LCP) 25
Cumulative Layout Shift (CLS) 25
First Contentful Paint (FCP) 10
Speed Index (SI) 10
Interaction to Next Paint (INP) 0

Ad scripts mostly hurt TBT (main-thread work) and CLS (slots that grow after load). Both together are 55% of the score.

Install and run Lighthouse from the command line

The Lighthouse README states that the CLI requires Node 22 (LTS) or later. Version 13.6.0 was current on npm when this guide was written.

npm install -g lighthouse
lighthouse https://www.example.com/article/ \
  --only-categories=performance \
  --output=json --output-path=./with-ads.json

Measure the ad impact: ads on vs ads off

The CLI flag --blocked-url-patterns blocks network requests matching a pattern. Run the same URL a second time with Google’s ad domains blocked:

lighthouse https://www.example.com/article/ \
  --only-categories=performance \
  --blocked-url-patterns="*googlesyndication.com*" \
  --blocked-url-patterns="*doubleclick.net*" \
  --output=json --output-path=./no-ads.json

Then compare the two reports:

// compare.mjs  (node compare.mjs with-ads.json no-ads.json)
import { readFileSync } from 'node:fs';
const [a, b] = process.argv.slice(2).map((f) => JSON.parse(readFileSync(f, 'utf8')));
const ids = ['largest-contentful-paint', 'total-blocking-time', 'cumulative-layout-shift'];
for (const id of ids) {
  console.log(id.padEnd(26), a.audits[id].numericValue.toFixed(2), '->', b.audits[id].numericValue.toFixed(2));
}
console.log('score'.padEnd(26), a.categories.performance.score, '->', b.categories.performance.score);

We tested these flags and the audit IDs with Lighthouse 13.6.0 on a local test page. Blocked requests are still counted in the report’s request totals, so compare timings and main-thread time rather than request totals.

Interpretation:

  • Large TBT drop with ads off: ad JavaScript dominates main-thread time. Fewer units above the fold or lazy loading lower slots may help (see lazy loading AdSense).
  • CLS falls to near zero with ads off: your slots are not reserving space. Fix that first; it is fully in your control (reserve space for ads).
  • LCP barely changes: your LCP problem is your own (hero image, fonts, server). Do not blame ads.

Keep these comparisons occasional. Each “ads on” run is a real page load that requests ads. Never click inside a test, and read testing ads safely before automating anything on monetized pages.

Where to see third-party cost in the report

Two parts of the Lighthouse 13 report matter for ads:

  • Third parties insight (third-parties-insight): a table by third-party entity with transfer size and main-thread time, with the individual URLs underneath.
  • Resource summary (resource-summary, hidden in the HTML report but present in JSON): request count and transfer size by type, including a third-party row.

Older guides refer to an audit called “third-party-summary”; in Lighthouse 13 look for the third-parties insight instead.

Set up Lighthouse CI

Lighthouse CI collects several runs, asserts budgets and uploads reports. The getting-started guide installs it with npm install -g @lhci/cli@0.16.x; @lhci/cli 0.16.1 depends on Lighthouse 13.6.0.

  1. Add a lighthouserc.json at the repository root.
  2. Run lhci autorun locally to check it.
  3. Add the same command to your CI workflow after the build step.

This configuration audits a built static site with ad requests blocked, so CI never generates ad impressions, and checks budgets on what you control:

{
  "ci": {
    "collect": {
      "staticDistDir": "./dist",
      "numberOfRuns": 3,
      "settings": {
        "onlyCategories": ["performance"],
        "blockedUrlPatterns": ["*googlesyndication.com*", "*doubleclick.net*"]
      }
    },
    "assert": {
      "assertions": {
        "cumulative-layout-shift": ["error", { "maxNumericValue": 0.1 }],
        "largest-contentful-paint": ["warn", { "maxNumericValue": 2500 }],
        "total-blocking-time": ["warn", { "maxNumericValue": 300 }],
        "resource-summary:third-party:count": ["warn", { "maxNumericValue": 30 }],
        "resource-summary:third-party:size": ["warn", { "maxNumericValue": 500000 }]
      }
    },
    "upload": { "target": "filesystem", "outputDir": "./lhci-reports" }
  }
}

We ran this exact file with @lhci/cli 0.16.1 against a local test page: three runs, assertions checked, reports written to disk. The budget numbers are starting points, not recommendations from Google; tune them to your current median and tighten over time.

Key options, per the configuration reference:

Option What it does
numberOfRuns runs per URL (default 3); a representative median run is used
maxNumericValue upper bound on an audit’s numeric value; bytes for resource-summary sizes in LHCI assertions
minScore lower bound on an audit or category score
preset lighthouse:recommended, lighthouse:all or lighthouse:no-pwa
upload.target lhci (your own server), temporary-public-storage or filesystem

Note that budget.json files use kilobytes while LHCI assertions use bytes, as the configuration docs point out.

Privacy of uploaded reports

temporary-public-storage puts reports on a public URL for a few days. The getting-started guide warns about exactly that. For a site under development, filesystem or a self-hosted Lighthouse CI server keeps reports private.

Which pages and which device to test

By default, staticDistDir makes Lighthouse CI find HTML files on disk by itself. On a content site that can mean hundreds of pages, most of them using the same template. The configuration reference describes a url array for this case: when it is set together with staticDistDir, automatic detection is disabled and the port of each URL is replaced with the port of the local server LHCI starts, so you can write paths like this:

"collect": {
  "staticDistDir": "./dist",
  "url": [
    "http://localhost/index.html",
    "http://localhost/guides/some-article/index.html",
    "http://localhost/category/recipes/index.html"
  ]
}

Pick one URL per template that carries ads: home, a long article with in-content units, a category or list page. That keeps CI fast and makes regressions easy to attribute.

For the device, the Lighthouse CLI scores pages as mobile unless told otherwise. Its help output lists --preset with the choices perf, experimental and desktop, and recommends --preset=desktop over --form-factor=desktop for desktop runs. Ad layouts often differ between mobile and desktop (anchor ads, side rails, different unit sizes), so if you run both, keep them as separate reports and never mix them in one comparison.

A practical routine for ad-supported sites

  1. In CI, on every build: ads blocked, assertions on CLS, your own JavaScript and image weight.
  2. Monthly or after an ad layout change: one manual ads-on vs ads-off comparison on three representative templates (home, article, category), five runs each.
  3. Continuously: field data. Lab improvements only count if CrUX or your real-user data move too.

Common mistakes

  • Optimising the score instead of the page. A 100 with ads blocked tells you nothing about what readers get.
  • Running Lighthouse CI against production with live ads on every push. It generates automated ad requests for no benefit.
  • Comparing a desktop run with a mobile run. Keep the preset identical across comparisons.
  • Hard-failing on third-party metrics. Ad creatives change daily; use warnings.
  • Ignoring layout shift because “it’s the ad”. The space an ad slot occupies is your markup’s responsibility.

Open-source tools mentioned

ToolLicence
LighthouseApache-2.0
Lighthouse CIApache-2.0

Frequently asked questions

Does running Lighthouse on my live pages create AdSense impressions?

A Lighthouse run loads the page in Chrome, so unless you block ad requests, the ad code runs and requests ads like any other page load. Keep runs against live ad pages few and occasional, never click anything, and prefer blocking ad domains or testing a staging copy without live ad code for routine CI. Automated page loads are a classic source of invalid traffic, so do not schedule heavy automated runs on monetized pages.

Why is my Lighthouse score different every run?

Ad auctions return different creatives, sizes and scripts on each load, and network and CPU conditions vary. Lighthouse CI runs three times per URL by default and uses a representative median run; the default assertion aggregation is optimistic. Increase numberOfRuns to five for noisy ad pages and compare medians rather than single runs.

Why does Lighthouse show INP as zero weight?

In the default Lighthouse 13 config, Interaction to Next Paint is listed in the performance category with weight 0, because a navigation run does not include real user interactions. Total Blocking Time, weighted 30%, is the lab signal most related to responsiveness. Measure INP from real users with the web-vitals library or CrUX.

Should I fail the build when third-party scripts grow?

A warning is usually better than a failure, because ad scripts change without any commit on your side. Use warn-level assertions on resource-summary:third-party:count and size to see drift, and error-level assertions on things you control, such as layout shift from reserved ad slots or your own script weight.

Sources

  1. Lighthouse README · GoogleChrome on GitHub
  2. Lighthouse default config (core/config/default-config.js) · GoogleChrome on GitHub
  3. Lighthouse CI: Getting Started · GoogleChrome on GitHub
  4. Lighthouse CI: Configuration · GoogleChrome on GitHub