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.
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 |
|---|---|---|---|
| Performance | 0.85 | 0.90+ | Varies ±5 points — use metric assertions |
| Accessibility | 0.90 | 1.00 | Stable score, target 100 |
| Best Practices | 0.90 | 1.00 | HTTPS, console errors, deprecated APIs |
| SEO | 0.90 | 1.00 | Meta tags, canonical, robots.txt |
| LCP | < 2500ms | < 1800ms | Largest Contentful Paint |
| TBT | < 200ms | < 100ms | Total Blocking Time (INP proxy) |
| CLS | < 0.1 | < 0.05 | Cumulative 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
- Score varies run-to-run — Use numberOfRuns: 3, assert on specific metrics not aggregate score
- Server not ready before collect — Tune startServerReadyPattern to match your server's ready log message
- Chrome not found in CI — Add
apt-get install -y google-chrome-stableor use--chrome-flags="--no-sandbox" - Auth-protected pages show 0 scores — Add puppeteerScript to lighthouserc.js to log in before auditing
- Performance budget too strict — Use warn instead of error for non-critical assertions during initial setup
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.
Related Products
on GumroadPremium Workflow Pack
Production-grade workflows, architecture guides, and deployment scripts for teams that ship. 10 advanced CI/CD workflows (blue-green, canary, E2E, security), 5 architecture deep-dives, code review checklist, PR process guide, and 5 battle-tested Bash deployment scripts.
Buy on Gumroad →GitHub Actions CI/CD Templates Pack
12 production-ready GitHub Actions workflow templates covering Node.js, Python, Docker, multi-environment deployments, security scanning, and auto-changelog. Copy, paste, ship.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
Web Performance Checklist
Interactive web performance checklist covering images, fonts, JavaScript, CSS, caching, and server. Check off items to track your score out of 100 and export as Markdown.
Open free tool →
Lighthouse Score Simulator
Estimate Lighthouse performance scores based on JS bundle size, CSS, images, TTFB, and render-blocking resources. Get LCP, FID, CLS, FCP estimates.
Open free tool →
Web Vitals Scorer
Check your Core Web Vitals scores. Enter LCP, INP, and CLS values to see instant Pass/Fail ratings with Good/Needs Improvement/Poor thresholds and optimization tips.
Open free tool →
More Free Tools
Related Articles
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.
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.
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.
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.
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.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →