Testland
Browse all skills & agents

lighthouse-perf

Configures Lighthouse CI (`@lhci/cli`) to audit Web Vitals (LCP, INP, CLS) on every PR, asserts against canonical thresholds (LCP ≤2.5s, INP ≤200ms, CLS ≤0.1 at the 75th percentile), uploads Lighthouse reports as build artifacts, and posts deltas as PR comments. Includes a budget-authoring reference: per-route LCP/INP/CLS thresholds by traffic class (cached / dynamic / api-heavy / form-heavy / media-heavy) via `assertMatrix`, plus `budget.json` resource-size caps (JS / CSS / images / total bytes). Use when the project ships a web frontend and the team needs continuous Web Vitals monitoring tied to PR gating, or needs its first Lighthouse budgets drafted.

Install with skills.sh (any agent)

npx skills add testland/qa --skill lighthouse-perf
View source

lighthouse-perf

Overview

The Core Web Vitals are Google's three canonical user-experience metrics (web-vitals (opens in new window)):

MetricMeasures"Good" threshold
LCP (Largest Contentful Paint)Loading performance2.5 seconds
INP (Interaction to Next Paint)Interactivity200 milliseconds
CLS (Cumulative Layout Shift)Visual stability0.1

INP became a stable Core Web Vital in 2024, replacing FID (web-vitals (opens in new window)). The canonical measurement standard is the 75th percentile of page loads, segmented across mobile and desktop (web-vitals (opens in new window)).

This skill covers Lighthouse CI (@lhci/cli) - the official Google Chrome team tool for running Lighthouse on every PR and asserting against budgets (lhci (opens in new window)).

When to use

  • The project ships a web frontend (Next.js, Vite, Remix, plain static, etc.).
  • The team has documented Web Vitals NFRs (per non-functional-requirement-extractor) and needs CI enforcement.
  • A PR's perf delta vs. main needs to be visible (regression-block or just-warn).
  • The team uses Lighthouse for accessibility / SEO / best-practices audits beyond perf.

If the project is a backend API or a CLI tool, this skill doesn't apply - use k6-load-testing or a sibling load runner for backend perf.

Install

npm install --save-dev @lhci/cli

(Per lhci (opens in new window); the docs reference @lhci/cli@0.15.x as the current major.) Pin to a specific minor in CI for determinism.

Configure

Create .lighthouserc.js (or .lighthouserc.json) at the project root. The canonical shape per lhci (opens in new window):

module.exports = {
  ci: {
    collect: {
      // What to audit
      url: [
        'http://localhost:3000/',
        'http://localhost:3000/dashboard',
        'http://localhost:3000/pricing',
      ],
      // How many runs per URL - median report wins; 3 is canonical for stability
      numberOfRuns: 3,
      // Lighthouse settings
      settings: {
        preset: 'desktop',                       // or 'mobile' (default)
        chromeFlags: '--no-sandbox',              // CI-runner-friendly
      },
      // Use a static-server when running headless in CI
      startServerCommand: 'npm run start',
      startServerReadyPattern: 'ready on',
    },
    assert: {
      // Canonical Web Vitals budgets per web.dev/articles/vitals
      assertions: {
        'largest-contentful-paint': ['error', { maxNumericValue: 2500 }],   // 2.5s
        'interaction-to-next-paint': ['error', { maxNumericValue: 200 }],   // 200ms
        'cumulative-layout-shift':   ['error', { maxNumericValue: 0.1 }],    // 0.1
        // Lighthouse category scores (0-1)
        'categories:performance':    ['warn',  { minScore: 0.9 }],
        'categories:accessibility':  ['error', { minScore: 0.95 }],
        'categories:best-practices': ['warn',  { minScore: 0.9 }],
      },
    },
    upload: {
      // Where to upload the .json reports for trend analysis
      target: 'temporary-public-storage',   // or 'lhci' for self-hosted server
    },
  },
};

Assertion levels per lhci (opens in new window):

  • 'error' - fails the CI run (exits non-zero).
  • 'warn' - surfaces in the report but doesn't fail.
  • 'off' - disabled (useful for opt-out per-page).

Running

The canonical invocation per lhci (opens in new window):

lhci autorun

autorun runs three phases in sequence:

  1. collect - start the server (if startServerCommand set), run Lighthouse N times per URL.
  2. assert - compare results against the assertion config; exit non-zero on error-level failures.
  3. upload - upload reports to the configured target for trend tracking.

For finer control, the phases can run independently: lhci collect, lhci assert, lhci upload.

Running specific URLs

For a single PR-relevant audit:

lhci collect --url=http://localhost:3000/dashboard --numberOfRuns=3
lhci assert

CI integration

# .github/workflows/lighthouse.yml
name: lighthouse

on:
  pull_request:
    paths:
      - 'src/**'
      - 'package.json'
      - 'package-lock.json'

jobs:
  lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - run: npm ci

      - name: Build
        run: npm run build

      - name: Lighthouse CI
        env:
          LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}   # optional, for PR comments
        run: npx lhci autorun

      - name: Upload Lighthouse reports
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: lighthouse-reports
          path: .lighthouseci/
          retention-days: 14

The optional LHCI_GITHUB_APP_TOKEN (set up via the Lighthouse CI GitHub App) enables PR comments showing the per-metric delta vs. the main branch's last green run.

Authoring budgets

Budget authoring is part of Lighthouse CI configuration: picking per-route LCP / INP / CLS thresholds by traffic class, resource-size caps in budget.json, the assertMatrix config shape, and how to validate a new budget against production before committing it, are all in references/budgets.md. Start there when the project has no budgets yet or the existing ones need a redesign.

Mobile vs desktop budgets

LCP / INP thresholds are the same across mobile and desktop, but mobile is consistently slower in practice - the same JS bundle runs on a less-powerful CPU over a less-stable network.

Common pattern: separate .lighthouserc.mobile.js and .lighthouserc.desktop.js, run both in CI. The mobile run uses preset: 'mobile' (default) which applies CPU + network throttling to simulate a mid-range Android device.

# Run both
LHCI_BUILD_CONTEXT__GITHUB_BASE_URL=https://github.com/... \
  npx lhci autorun --config=.lighthouserc.mobile.js
npx lhci autorun --config=.lighthouserc.desktop.js

Anti-patterns

Anti-patternWhy it failsFix
numberOfRuns: 1Single-run measurements are noisy; flaky alerts.Use 3 (canonical) or 5 for high-stakes pages; LHCI uses the median.
Asserting on first-input-delay (FID)FID was retired in 2024 (web-vitals (opens in new window)).Use interaction-to-next-paint (INP).
Hard error on every metric out of the boxExisting pages may not meet thresholds; team learns to ignore the gate.Start with warn for everything; promote to error once green for 2 weeks.
Auditing only the homepageThe homepage is usually the most-optimized page; misses regressions on long-tail routes.Audit a representative URL set: home + 1 logged-in dashboard + 1 long-form content + 1 form-heavy.
Lighthouse score as the sole metricLighthouse score conflates multiple subscores; doesn't isolate which Web Vital regressed.Assert on the individual Web Vitals (largest-contentful-paint, interaction-to-next-paint, cumulative-layout-shift); category score is supplementary.
Running against productionLighthouse fires real network requests and triggers analytics; pollutes prod metrics.Always against staging or a local build.

Lab vs field

Lighthouse CI measures lab data (synthetic; deterministic runner). Field data (real-user metrics, RUM) is measured by Web Vitals JS in production. Both matter:

SourceToolUse for
Lab (synthetic)Lighthouse CIPer-PR regression gate.
Field (RUM)web-vitals library + analyticsReal-user 75th-percentile tracking.

Lighthouse CI catches per-PR regressions; field data tracks the 75th-percentile threshold per web-vitals (opens in new window). Don't substitute one for the other.

References

  • web-vitals (opens in new window) - canonical Core Web Vitals definitions and thresholds (LCP ≤2.5s, INP ≤200ms, CLS ≤0.1; 75th-percentile measurement; INP-replaces-FID in 2024).
  • lhci (opens in new window) - Lighthouse CI canonical install, lhci autorun, configuration shape, assertion levels.
  • references/budgets.md - drafting per-route budgets and budget.json resource-size caps at design time.
  • perf-budget-gate - downstream unified gate aggregating Lighthouse + load-runner verdicts.
  • non-functional-requirement-extractor - upstream skill that surfaces Web Vitals NFRs from PRDs.

Authoring Lighthouse budgets

View source (opens in new window)

Authoring Lighthouse budgets

Drafting a .lighthouserc.js assertion config and a budget.json resource-size budget at design time, so the Lighthouse CI runner has something meaningful to assert against. Without this workflow, teams either (a) set every threshold to the "good" default and ignore route-specific reality, or (b) pick thresholds via guesswork. Either ends with a gate the team disables.

The two artifacts:

  1. Lighthouse CI assertion config in .lighthouserc.js - per-route LCP / INP / CLS thresholds.
  2. Resource-size budget in budget.json (the Lighthouse "performance budgets" feature) - per-resource-type byte caps.

Step 1 - Inventory the routes

For each route to be audited:

FieldNotes
URL patternThe actual URL or a representative one.
Traffic classcached / dynamic / api-heavy / form-heavy / media-heavy.
Auth statepublic / logged-in (auth state changes the JS bundle).
Cache TTLStatic assets duration.
User-tier trafficWhat % of traffic does this route account for? Drives strictness.

The URL set should cover the team's high-traffic routes plus any known-slow long-tail page. Don't audit every URL - pick representatives.

Step 2 - Pick LCP / INP / CLS thresholds per route

Start from the canonical Web Vitals "good" thresholds (LCP ≤2.5s, INP ≤200ms, CLS ≤0.1) and adjust per traffic class:

Traffic classLCP targetINP targetCLS targetReasoning
Cached (CDN-served, mostly static)≤1.5s≤100ms≤0.1The default is too lenient; cached pages should be fast.
Dynamic (per-user content)≤2.5s≤200ms≤0.1Default thresholds.
API-heavy (waterfall of fetches)≤3.0s≤200ms≤0.1Acknowledge real-world latency; tighten elsewhere.
Form-heavy (input + validation)≤2.5s≤100ms≤0.05INP matters more - every keystroke is an interaction. CLS strict because forms must not jump.
Media-heavy (images / video)≤2.5s≤200ms≤0.1LCP via priority hints + loading=eager on hero.

For a team's first pass, start lenient (Web Vitals defaults across the board) and tighten one route at a time as evidence accumulates that the route is consistently faster than the default.

Step 3 - Pick resource-size budgets

A resource-size budget caps the total bytes per resource type. The canonical Lighthouse "good" defaults for a non-media-heavy public page:

Resource typeSuggested budgetNotes
script300 kbCompressed JS bundle (gzip / brotli). Tighten to 150kb for marketing pages.
stylesheet100 kbCSS only. Most projects fit easily.
image500 kbPer page - adjust upward for media-heavy.
font100 kbSubset fonts; use variable fonts when possible.
total1500 kbPage total; CDN-cached or not.

For Single-Page Apps where the JS bundle is the load-bearing cost, the JS budget is the most important. Subpaths (route chunks) keep this tractable as the app grows.

Step 4 - Emit lighthouserc.js

A representative config that lives at the project root:

// .lighthouserc.js
module.exports = {
  ci: {
    collect: {
      url: [
        'http://localhost:3000/',                      // marketing home (cached)
        'http://localhost:3000/pricing',               // marketing pricing (cached)
        'http://localhost:3000/dashboard',             // logged-in dynamic
        'http://localhost:3000/orders/new',            // form-heavy
      ],
      numberOfRuns: 3,
      settings: {
        preset: 'desktop',
        chromeFlags: '--no-sandbox',
        budgetPath: './budget.json',                  // resource-size budget
      },
      startServerCommand: 'npm run start',
      startServerReadyPattern: 'ready on',
    },
    assert: {
      assertMatrix: [
        // Cached marketing pages - strict
        {
          matchingUrlPattern: '^http://[^/]+/(pricing)?$',
          assertions: {
            'largest-contentful-paint': ['error', { maxNumericValue: 1500 }],
            'interaction-to-next-paint': ['error', { maxNumericValue: 100 }],
            'cumulative-layout-shift':   ['error', { maxNumericValue: 0.1 }],
          },
        },
        // Dynamic logged-in pages - defaults
        {
          matchingUrlPattern: '/dashboard',
          assertions: {
            'largest-contentful-paint': ['error', { maxNumericValue: 2500 }],
            'interaction-to-next-paint': ['error', { maxNumericValue: 200 }],
            'cumulative-layout-shift':   ['error', { maxNumericValue: 0.1 }],
          },
        },
        // Form-heavy pages - strict CLS
        {
          matchingUrlPattern: '/orders/new',
          assertions: {
            'largest-contentful-paint': ['error', { maxNumericValue: 2500 }],
            'interaction-to-next-paint': ['error', { maxNumericValue: 100 }],
            'cumulative-layout-shift':   ['error', { maxNumericValue: 0.05 }],
          },
        },
      ],
    },
    upload: { target: 'temporary-public-storage' },
  },
};

assertMatrix lets per-route assertions live in one config - easier to review than separate config files.

Step 5 - Emit budget.json

Lighthouse's resource-size budget format:

[
  {
    "path": "/*",
    "resourceSizes": [
      { "resourceType": "script",     "budget": 300 },
      { "resourceType": "stylesheet", "budget": 100 },
      { "resourceType": "image",      "budget": 500 },
      { "resourceType": "font",       "budget": 100 },
      { "resourceType": "total",      "budget": 1500 }
    ],
    "resourceCounts": [
      { "resourceType": "third-party", "budget": 10 }
    ]
  },
  {
    "path": "/marketing/*",
    "resourceSizes": [
      { "resourceType": "script",     "budget": 150 },
      { "resourceType": "stylesheet", "budget": 50 },
      { "resourceType": "total",      "budget": 800 }
    ]
  }
]

Per-path budgets allow stricter targets for marketing pages (where load time directly impacts conversion) than for logged-in app routes.

Step 6 - Validate the budget realistically

Before committing, run Lighthouse against current production with the new config:

LHCI_BUILD_CONTEXT__GITHUB_BASE_URL=... npx lhci collect --url=https://prod.example.com/
npx lhci assert

Expect some failures - that's the point. The budget surfaces what needs work. Categorize the failures:

Failure kindDecision
Single-route outlierFile a perf-improvement ticket; relax the budget on this route only with a TODO.
Universal failureThe budget is too strict; relax to current p75 + 10%.
Budget violated only on mobile presetAdd a separate lighthouserc.mobile.js with looser mobile budgets.

Never set a budget that always passes today - it'll never catch a regression.

Anti-patterns

Anti-patternWhy it failsFix
Same threshold for every routeCached marketing page passes the same gate as a logged-in dashboard.Use assertMatrix with per-route patterns.
Threshold = current production valueNo room for a real regression to be caught.Set threshold = current + 10% headroom; tighten over time.
Budgets in one mega-file with no per-path scopeStrict marketing budget falsely fails the dashboard.Per-path budget objects.
Setting the threshold to the "Good" target on day oneMost production sites don't meet the targets out of the box; team disables the gate.Land the gate at current production levels first; tighten the budget as a separate task.
Skipping the resource-size budgetWeb Vitals catch the symptom (slow LCP); resource-size catches the cause (JS bundle bloat).Both. They're complementary.

References

  • web.dev/articles/vitals - canonical LCP / INP / CLS thresholds at the 75th percentile.
  • Lighthouse performance budgets - https://web.dev/articles/use-lighthouse-for-performance-budgets

Related skills

db-query-plan-analyzer

Reads `EXPLAIN` / `EXPLAIN ANALYZE` output from PostgreSQL, MySQL, or SQLite - identifies the dominant cost (sequential scan, nested loop, sort spill, missing index, type-cast preventing index use), proposes the specific index or query rewrite to fix it, and emits the candidate `CREATE INDEX` statement. Use when load testing or production telemetry shows the database as the bottleneck and the team needs targeted query-level remediation.

flame-graph-analyzer

Reads CPU flame-graph output from py-spy (Python), async-profiler (JVM), Go pprof, or Node.js `perf_hooks` / clinic.js: identifies the hot path (top sample-time frames), classifies the bottleneck (CPU-bound vs lock contention vs allocator pressure), and proposes the next investigation step. Use when a perf regression is bisected to a commit but the hot path inside it is unclear; for tail-latency percentiles use the latency-percentiles reference in k6-load-testing, and for a slow SQL hot path use db-query-plan-analyzer.

jmeter-load-testing

Authors Apache JMeter `.jmx` test plans (Thread Groups + HTTP samplers + assertions + listeners) in the JMeter GUI, runs them headlessly via `jmeter -n -t plan.jmx -l results.jtl`, generates an HTML dashboard with `-e -o`, and gates CI on JTL parsing. Use when the project has an existing JMeter investment, needs JVM-native load tooling, or works in domains with strong JMeter community support (banking, telecom, enterprise).

k6-load-testing

Authors k6 JavaScript load-test scripts (VU loops + checks + sleeps), configures the `options` block with `stages` (ramp-up patterns) and `thresholds` (p(95) latency, error rate), runs via `k6 run script.js` or `--vus / --duration` ad-hoc flags, and uses thresholds as the CI pass/fail signal. Includes a latency-percentile interpretation reference: tail ratio (p99/p50), bimodal-distribution detection, coordinated omission and why naive p99 is optimistic, and constant-vus vs constant-arrival-rate executors. Use when the project ships HTTP / WebSocket / gRPC load tests and the team wants developer-friendly JavaScript authoring, or when a k6 threshold passes but the system still feels slow.

load-testing-overview

Teaches load and performance testing from zero: a tool-selection table choosing between k6, JMeter, Gatling, Locust, and Artillery from observable project facts; the six load profiles (smoke, average-load, stress, spike, soak, breakpoint); open vs closed workload models; why percentiles beat averages; turning a run into a pass/fail CI gate with a first runnable k6 script; a performance-incident triage workflow (confirm with a k6 smoke run, flame-graph the hot path, check slow queries, localize the cause); and full Gatling (Simulation DSL, injectOpen/injectClosed, setUp().assertions()) and Locust (HttpUser + @task locustfile, headless / distributed runs, CSV gating) deep dives in references. Use when a service needs performance coverage and the tool, load profile, or pass/fail threshold has not been decided yet, or when a live performance incident needs cause localization.

perf-budget-gate

Builds a unified release-readiness gate that aggregates verdicts from any combination of k6 / JMeter / Gatling / Locust load runners and Lighthouse CI Web Vitals, applies severity-aware pass/fail thresholds, and emits a single go / no-go decision with per-metric deltas vs the main-branch baseline. Posts the delta as a PR comment when the team has the integration set up. Use when authoring a CI step that gates a deployment on cross-runner perf compatibility.

slo-load-test-plan

Turns a service's SLOs and endpoint traffic mix into a named scenario matrix: one scenario per SLO boundary condition, a load profile (smoke, average-load, stress, soak, spike, breakpoint) per scenario, an open or closed workload injection model, a threshold expression derived from the SLO the scenario guards, and an error-budget calculation that sets the soak run's failure allowance. Stays runner-agnostic and fixes the pass/fail line before any tool is configured. Use when an SLO document and an endpoint list both exist but nobody has decided which load runs to make, what shape of load each carries, or what number would count as a failure.

web-vitals-inp-deep

Deep INP (Interaction to Next Paint) testing: decomposes input delay, processing duration, and presentation delay via the web-vitals/attribution build, asserts per-interaction INP budgets in Playwright using PerformanceObserver plus the web-vitals visibilitychange flush, and identifies long tasks blocking the main thread. Use when a page feels unresponsive while LCP and CLS are green, or to gate key interactions (form submit, modal open, route change) under an INP budget in CI. Covers interactions only - for page-load Web Vitals gating use lighthouse-perf; for service-worker cache-strategy latency use the qa-pwa plugin's service-worker skills.