To run Astro Lighthouse tests properly, build the site first (npm run build && npm run preview) and test the preview or the deployed URL, never astro dev, because the dev server serves unbundled code. Lighthouse in Chrome DevTools and PageSpeed Insights give you lab scores; Search Console and the Chrome UX Report show what real visitors experience; Lighthouse CI and the web-vitals library keep watching after launch.
This guide covers nine tools, what each measures, and how to use them on an Astro 7 site without fooling yourself.
Key Takeaways
- Never measure
astro dev. Testastro previewlocally or the production URL.- Lab tools (Lighthouse, WebPageTest) are for debugging; field data (CrUX, Search Console) is what Google uses for Core Web Vitals.
- Run Lighthouse in an incognito window with throttling on, and compare medians of several runs.
- Lighthouse CI in GitHub Actions catches regressions before they ship.
- The
web-vitalslibrary gives you real-user LCP, INP and CLS from your own visitors.
Lab data vs field data
Every speed tool falls into one of two groups:
| Lab data | Field data | |
|---|---|---|
| Source | one simulated load on a test machine | real Chrome users over 28 days |
| Tools | Lighthouse, WebPageTest, DevTools | CrUX, Search Console, PageSpeed Insights (top section), RUM |
| Good for | debugging, before/after comparisons | knowing what users actually get |
| Available | instantly, for any URL | only once a page has enough traffic |
Google’s page experience signals use field data. A Lighthouse score of 100 on your laptop doesn’t guarantee good Core Web Vitals for a visitor on a mid-range phone, and a lower lab score doesn’t mean users are suffering. Use both. The Core Web Vitals guide explains each metric and how Astro affects it.
1. Lighthouse in Chrome DevTools
Built into Chrome. Open DevTools, choose the Lighthouse panel, pick Mobile, and run.
npm run build
npm run preview
# then open http://localhost:4321 in an incognito window and run Lighthouse
Tips for useful results:
- Use an incognito window so extensions don’t skew the numbers.
- Keep the default mobile throttling; it’s closer to real users than an unthrottled desktop.
- Run three to five times and look at the median. Scores vary from run to run.
- Read the Diagnostics and Opportunities sections. They matter more than the score.
2. PageSpeed Insights
PageSpeed Insights (pagespeed.web.dev) runs Lighthouse on Google’s servers and, for pages with enough traffic, shows CrUX field data above the lab results. It’s the quickest way to see both views for a deployed URL.
The top section answers “are real users getting good Core Web Vitals?” The bottom section answers “what can I fix?” If the field section says “no data,” the page doesn’t have enough Chrome traffic yet; rely on lab data and RUM.
3. WebPageTest
WebPageTest (webpagetest.org) tests from real browsers in many locations and connection types, and produces a detailed waterfall, filmstrip and video of the load. It’s the best tool for questions like “why does the LCP image start downloading so late?” or “what does a first visit from another continent look like?”
Use it after a deploy to compare hosts or CDN settings. For an Astro static site, the waterfall should show the HTML, one or two CSS files, fonts and images, with very little JavaScript. Anything else deserves a look.
4. Chrome DevTools Performance and Network panels
When a metric is bad, the Performance panel tells you why. Record a page load and inspect:
- LCP element and when it rendered.
- Long tasks on the main thread, which hurt INP.
- Layout shifts, highlighted with the element that moved.
The Network panel with “Disable cache” and a throttled profile shows what loads and in what order. Filter by JS to confirm islands only load when their client:* directive says they should. The lazy-load islands tip shows how to verify client:visible.
5. Search Console Core Web Vitals report
Once your site is verified in Google Search Console, the Core Web Vitals report groups URLs as Good, Needs improvement or Poor based on field data, for mobile and desktop separately. Because it groups similar URLs together, a problem in one layout shows up as a whole group of pages.
It’s slow to update (it uses a 28-day window) but it’s the closest thing to Google’s own view. Check it monthly and after major changes.
6. Chrome UX Report (CrUX)
CrUX is the public dataset behind the field data in PageSpeed Insights and Search Console. You can query it directly through the CrUX API or the CrUX History API to track your origin’s LCP, INP and CLS over time, and compare against competitors’ origins. It only includes sites with enough Chrome traffic.
7. Lighthouse CI
Lighthouse CI runs Lighthouse on every pull request and fails the build when scores or metrics fall below your budget:
// lighthouserc.json
{
"ci": {
"collect": {
"staticDistDir": "./dist",
"url": ["http://localhost/index.html", "http://localhost/blog/index.html"],
"numberOfRuns": 3
},
"assert": {
"assertions": {
"categories:performance": ["error", { "minScore": 0.9 }],
"largest-contentful-paint": ["warn", { "maxNumericValue": 2500 }],
"cumulative-layout-shift": ["error", { "maxNumericValue": 0.1 }]
}
}
}
}
npm run build
npx @lhci/cli autorun
staticDistDir lets Lighthouse CI serve the dist/ folder itself, which suits static Astro builds. The Lighthouse CI tip has a complete GitHub Actions workflow.
8. Real-user monitoring with web-vitals
The web-vitals library, from the Chrome team, measures LCP, INP, CLS, FCP and TTFB in your visitors’ browsers. Send the values to any endpoint or analytics tool:
---
// src/components/WebVitals.astro
---
<script>
import { onCLS, onINP, onLCP } from 'web-vitals';
function send(metric: { name: string; value: number; id: string }) {
const body = JSON.stringify({ name: metric.name, value: metric.value, id: metric.id, path: location.pathname });
navigator.sendBeacon?.('/api/vitals', body);
}
onCLS(send);
onINP(send);
onLCP(send);
</script>
Add it to your base layout. Because it’s a processed Astro script, it’s bundled and loaded once per page. On a static site without an endpoint, send the values to an analytics tool that accepts custom events instead. Some hosts, including Cloudflare Web Analytics, also report Core Web Vitals without any code. The privacy-friendly analytics tip compares options.
9. Astro’s own tools
Astro has two built-in aids:
- The dev toolbar audit. In
astro dev, the toolbar’s Audit app flags common performance and accessibility issues on the current page, such as images with an unoptimizedloadingattribute, large GIFs that should be videos, or islands that are slow to hydrate. It’s a hint, not a measurement, since dev mode is unoptimized. astro build --timings. Added in Astro 7.4 (October 2026), it reports where build time goes. That’s build speed rather than page speed, but on large sites it shows which routes or integrations slow deploys down. The build timings tip explains the output.
For JavaScript weight, the bundle size analysis tip shows how to visualize what each island ships.
A simple testing routine
- Before launch: Lighthouse on
astro previewfor each template (home, listing, article, contact), plus one WebPageTest run on the deployed URL. - On every pull request: Lighthouse CI with budgets for the key templates.
- Monthly: Search Console Core Web Vitals and PageSpeed Insights field data.
- Ongoing, for busy sites:
web-vitalsRUM to catch problems on specific devices or pages.
Komal Astro themes are static and ship no JavaScript unless a component opts in, which gives you a fast starting point; still measure your own build after adding content, fonts and images, since those decide most real-world results. The Astro performance guide covers fixes for what these tools find, and web.dev’s Core Web Vitals overview defines the thresholds.
FAQ
How do I run Lighthouse on an Astro site?
Build and preview the site with npm run build && npm run preview, open the preview URL in an incognito Chrome window, open DevTools, and run the Lighthouse panel in mobile mode. Don’t test astro dev, because the dev server serves unoptimized code.
Why is my Astro Lighthouse score lower in dev?
The dev server serves unbundled modules, injects the dev toolbar and skips production optimizations, so scores are always worse. Only astro preview or the deployed site reflect real performance.
Can an Astro site score 100 on Lighthouse?
Many static Astro pages can, because they ship little or no JavaScript. Large images, web fonts, third-party scripts and heavy islands are what usually pull the score down. Treat the score as a guide and focus on the individual metrics.
What’s the difference between Lighthouse and PageSpeed Insights?
Lighthouse is the testing engine that produces lab data. PageSpeed Insights runs Lighthouse on Google’s servers and also shows real-user field data from the Chrome UX Report, when the page has enough traffic.
Which speed metrics matter most for SEO?
Google’s Core Web Vitals: Largest Contentful Paint, Interaction to Next Paint and Cumulative Layout Shift, measured from real users. Check them in Search Console’s Core Web Vitals report or the field data section of PageSpeed Insights.