To run Lighthouse CI on an Astro site, build the site, point @lhci/cli at the dist/ folder with staticDistDir, and add assertions for the scores and metrics you care about. Lighthouse CI serves the static files itself, audits each page several times, and fails the CI job when a pull request pushes a score below your budget.
Key Takeaways
- Static Astro builds need no server for Lighthouse CI:
staticDistDir: './dist'is enough.- Audit a few representative URLs (home, a blog post, a listing page) rather than every page.
- Run three or more audits per URL; single Lighthouse runs vary.
- Start with warnings, then tighten to errors once you know your baseline.
Install and configure
# Terminal
npm install -D @lhci/cli
Create a config file in the project root:
{
"ci": {
"collect": {
"staticDistDir": "./dist",
"url": [
"http://localhost/",
"http://localhost/blog/",
"http://localhost/blog/astro-seo-guide/"
],
"numberOfRuns": 3
},
"assert": {
"assertions": {
"categories:performance": ["error", { "minScore": 0.9 }],
"categories:accessibility": ["error", { "minScore": 0.95 }],
"categories:seo": ["warn", { "minScore": 0.95 }],
"largest-contentful-paint": ["warn", { "maxNumericValue": 2500 }],
"cumulative-layout-shift": ["error", { "maxNumericValue": 0.1 }]
}
},
"upload": {
"target": "temporary-public-storage"
}
}
}
Save it as lighthouserc.json. With staticDistDir, Lighthouse CI starts its own static server on a random port and rewrites http://localhost/ URLs to it, so list paths as shown. If you leave out url, it audits the HTML files it finds in dist/, which is fine for a small site and slow for a large one.
Run it locally after a build:
# Terminal
npm run build && npx lhci autorun
autorun collects, asserts and uploads in one step. temporary-public-storage gives you a shareable report link for a few days. Use "target": "filesystem" instead if reports must not leave your CI.
Run it in GitHub Actions
# .github/workflows/lighthouse.yml
name: Lighthouse CI
on: [pull_request]
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build
- run: npx lhci autorun
Current Astro releases need Node.js 22.23.4 or newer; node-version: 22 resolves to the latest 22.x release. The job fails if any error assertion fails, which blocks the merge when you require the check. Our GitHub Actions workflows guide covers caching and deploy steps you can combine with this.
Choose budgets you can keep
A score of 100 on a CI runner is not a realistic target, because shared runners are slower and noisier than your laptop. A practical approach:
- Run
lhci autorunwith every assertion set towarnfor a week of pull requests. - Note the median scores per URL.
- Set
errorthresholds a few points below the median, so real regressions fail and noise does not.
Lab scores are a guide, not your users’ experience. Field data from real visitors, covered in our Core Web Vitals guide, tells you whether the site is actually fast. Lighthouse CI is best at catching the moment a new image, font or script makes things worse.
What usually breaks the budget
- A hero image without dimensions or with lazy loading (see the LCP image tip).
- A new
client:loadisland that could beclient:visibleor plain HTML. - A third-party embed loaded on every page.
- A web font added without
font-displayor preloading.
The themes in our catalog ship as static builds, so you can add this workflow to a theme project unchanged. The deploy docs cover where the same dist/ folder goes next.
FAQ
Does Lighthouse CI work with server-rendered Astro pages?
Yes, but you need a running server. Replace staticDistDir with startServerCommand, for example the astro preview command or your adapter’s start command, and list the full URLs to audit.
Why do my Lighthouse CI scores differ from PageSpeed Insights?
They run on different machines with different network and CPU throttling. Compare CI results with earlier CI results, not with PageSpeed Insights or your local Chrome.
How many URLs should Lighthouse CI audit?
One URL per page template is usually enough: the homepage, a listing page and a content page. More URLs make the job slower without catching many more problems.
Can Lighthouse CI comment on pull requests?
Yes, with the Lighthouse CI GitHub App and an LHCI_GITHUB_APP_TOKEN secret, it posts status checks with links to each report.