Skip to main content

Lighthouse CI Setup Guide

Automate Lighthouse performance audits on every pull request using GitHub Actions. Enforce performance budgets, track score trends, and block deploys when scores regress.

✓ GitHub Actions workflow ✓ Score thresholds ✓ Multiple URL auditing ✓ PR comment integration

Installation

# Install globally (local use)
npm install -g @lhci/cli

# Or add to your project
npm install --save-dev @lhci/cli

lighthouserc.js Configuration

// lighthouserc.js
module.exports = {
  ci: {
    collect: {
      // Build and serve your app, then audit these URLs
      startServerCommand: 'npm run start',
      startServerReadyPattern: 'ready on',
      url: [
        'http://localhost:3000/',
        'http://localhost:3000/pricing',
        'http://localhost:3000/dashboard',
      ],
      numberOfRuns: 3,   // median of 3 runs reduces score variance
      settings: {
        // Simulated throttling (default) — consistent across machines
        throttlingMethod: 'simulate',
        // Remove these for mobile simulation:
        // formFactor: 'mobile', screenEmulation: { mobile: true }
      },
    },
    assert: {
      preset: 'lighthouse:recommended',
      assertions: {
        // Fail CI if scores fall below these minimums
        'categories:performance':    ['error', { minScore: 0.9 }],
        'categories:accessibility':  ['error', { minScore: 0.9 }],
        'categories:best-practices': ['error', { minScore: 0.9 }],
        'categories:seo':            ['error', { minScore: 0.9 }],

        // Specific Web Vitals thresholds (more stable than aggregate score)
        'largest-contentful-paint':  ['error', { maxNumericValue: 2500 }],
        'total-blocking-time':       ['error', { maxNumericValue: 200 }],
        'cumulative-layout-shift':   ['error', { maxNumericValue: 0.1 }],
        'first-contentful-paint':    ['warn',  { maxNumericValue: 1800 }],

        // Resource budgets
        'uses-optimized-images':     'warn',
        'unused-javascript':         'warn',
        'render-blocking-resources': 'warn',
      },
    },
    upload: {
      target: 'temporary-public-storage',  // free 30-day storage
      // For GitHub PR comments, add LHCI_GITHUB_APP_TOKEN secret
      githubToken: process.env.LHCI_GITHUB_APP_TOKEN,
    },
  },
};

GitHub Actions Workflow

# .github/workflows/lighthouse-ci.yml
name: Lighthouse CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 20 }

      - name: Install dependencies
        run: npm ci

      - name: Build application
        run: npm run build

      - name: Run Lighthouse CI
        run: npx lhci autorun
        env:
          LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}

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

Lighthouse Score Targets

Category Minimum (CI Gate) Target Notes
Performance0.850.90+Varies ±5 points — use metric assertions
Accessibility0.901.00Stable score, target 100
Best Practices0.901.00HTTPS, console errors, deprecated APIs
SEO0.901.00Meta tags, canonical, robots.txt
LCP< 2500ms< 1800msLargest Contentful Paint
TBT< 200ms< 100msTotal Blocking Time (INP proxy)
CLS< 0.1< 0.05Cumulative Layout Shift

Self-Hosted LHCI Server

# Run LHCI server locally (stores results in SQLite)
npx @lhci/cli server --storage.storageMethod=sql \
  --storage.sqlDialect=sqlite \
  --storage.sqlDatabasePath=./lhci.db

# Or with Docker
docker run --rm -p 9001:9001 patrickhulce/lhci-server

# Update lighthouserc.js upload section to point to your server:
upload: {
  target: 'lhci',
  serverBaseUrl: 'http://lhci.internal:9001',
  token: process.env.LHCI_BUILD_TOKEN,
}

Common Issues & Fixes

Frequently Asked Questions

What is Lighthouse CI and how is it different from running Lighthouse manually?▼

Lighthouse CI (LHCI) is a command-line tool and server that automates Lighthouse audits in CI/CD pipelines, stores historical results, and compares scores between runs. Running Lighthouse manually in Chrome DevTools gives you a one-time snapshot. LHCI tracks every commit, shows score trends over time, fails the build when scores drop below your thresholds, and can post a summary comment on pull requests. It turns Lighthouse from a debugging tool into a continuous quality gate.

What should my Lighthouse score thresholds be?▼

Recommended minimums for production: Performance ≥ 90, Accessibility ≥ 90, Best Practices ≥ 90, SEO ≥ 90. For high-traffic e-commerce or SaaS, target ≥ 95 for Performance. Do not block CI on a score of 100 — scores fluctuate by 2-5 points due to timing variance. Use the assertions mode to set specific metric thresholds instead: first-contentful-paint, largest-contentful-paint, total-blocking-time, and cumulative-layout-shift are the most impactful Web Vitals.

How do I handle authentication in Lighthouse CI?▼

Use the puppeteerScript option in lighthouserc.js to run a Puppeteer script before Lighthouse audits. The script logs in, and Lighthouse inherits the authenticated browser context. Alternatively, use basicAuth credentials in the collect config for HTTP Basic Auth, or set authFlow using collectUrl with a login sequence. For apps behind feature flags, use extraHeaders to pass authentication tokens as HTTP headers.

Why does my Lighthouse Performance score vary between runs?▼

Lighthouse Performance scores vary because they measure real CPU and network timing, which is affected by CI machine load, throttling simulation, and JavaScript execution time. To reduce variance: run Lighthouse 3-5 times per audit (numberOfRuns: 3 in config) and use the median. Disable CPU throttling if your CI machines are consistent (--throttlingMethod=provided). Use a dedicated CI machine with consistent specs rather than shared runners. Scores will still vary by 2-5 points — set thresholds with a buffer.

How do I upload Lighthouse CI results to a dashboard?▼

LHCI has three storage backends. The LHCI Server (self-hosted Node.js app) stores results in SQLite/PostgreSQL and provides a web dashboard at port 9001. Temporary public storage (lhci.appspot.com) stores results for 30 days — free but public. Lighthouse CI also supports uploading to Google Cloud Storage or any S3-compatible bucket. For teams without a self-hosted server, the temporary storage with a --upload.githubToken to post PR comments is the quickest setup.

How do I prevent Lighthouse CI from failing on score fluctuation?▼

Use the assertions mode instead of numeric score thresholds. Assert on stable metrics like total-blocking-time (tbt) and cumulative-layout-shift (cls) rather than the aggregate performance score. Set median-run assertion to compare the median of multiple runs. Use warnOnly: true for metrics you want to monitor but not fail on. Set a permissive score threshold (e.g., minScore: 0.85) with --budgets-file for specific resource budgets like max JavaScript bundle size.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Related Articles

Mar 28, 2026 · 14 min read

Web Performance 2026: INP, Core Web Vitals & Lighthouse CI

Master web performance in 2026: INP replacing FID, LCP and CLS optimization, Lighthouse CI in GitHub Actions, RUM with web-vitals.js, and setting performance budgets to keep your site fast.

Apr 2, 2026 · 25 min read

Performance Optimization 2026: Complete Guide to Frontend, Backend, and Infrastructure

Comprehensive performance optimization guide for 2026 covering Core Web Vitals, JavaScript bundle optimization, server-side rendering, caching strategies, database query optimization, CDN configuration, and real-world benchmarks.

Apr 2, 2026 · 13 min read

Performance Testing in 2026: Beyond Page Load Times

A practical guide to performance testing in 2026 — Core Web Vitals, load testing, stress testing, soak testing, and building a performance culture that treats speed as a feature. Includes tooling recommendations and actionable measurement strategies.

Apr 2, 2026 · 23 min read

Web Performance and Core Web Vitals 2026: Complete Optimization Guide

Complete guide to Core Web Vitals optimization in 2026. Covers LCP, INP, CLS, TTFB optimization with real code examples. Includes Next.js, React, Vite, Cloudflare Workers, and backend optimization strategies for achieving 90+ Lighthouse scores.

Mar 28, 2026 · 12 min read

Nx vs Turborepo CI Performance: Build Caching, Affected Commands, and Real Benchmarks 2026

Benchmark-driven comparison of Nx and Turborepo CI performance. Covers remote caching strategies, affected/changed detection, GitHub Actions integration, and migration guide.

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →