Lighthouse helps you check how fast and user-friendly your Astro website is. It shows what to fix to make your site better.
Performance auditing with Lighthouse in Astro
Introduction
Syntax
Astro
lighthouse <URL> --output html --output-path ./report.html
Run this command in your terminal to audit your live Astro site by replacing with your site address.
The report.html file will show detailed results you can open in a browser.
Examples
Astro
lighthouse https://example-astro-site.com --output html --output-path ./astro-report.html
Astro
lighthouse http://localhost:3000 --output json --output-path ./local-report.jsonSample Program
This Node.js script runs Lighthouse on your Astro site URL and saves the report as an HTML file. It logs success or errors in the console.
Astro
import { exec } from 'node:child_process'; const url = 'https://example-astro-site.com'; const command = `lighthouse ${url} --output html --output-path ./astro-report.html`; exec(command, (error, stdout, stderr) => { if (error) { console.error(`Error running Lighthouse: ${error.message}`); return; } console.log('Lighthouse audit completed. Report saved as astro-report.html'); });
Important Notes
Make sure you have Lighthouse installed globally with npm install -g lighthouse before running commands.
Run audits on a stable internet connection for accurate results.
Open the generated HTML report in a browser to see detailed suggestions and scores.
Summary
Lighthouse helps you find ways to improve your Astro site's speed and usability.
Run Lighthouse from the command line with your site URL to get a detailed report.
Use the report to fix issues and make your site better for all users.
Practice
1. What is the main purpose of using
Lighthouse with an Astro site?easy
Solution
Step 1: Understand Lighthouse's role
Lighthouse is a tool designed to analyze websites and provide reports on performance, accessibility, SEO, and best practices.Step 2: Relate to Astro site improvement
Using Lighthouse on an Astro site helps find ways to improve speed and usability, making the site better for users.Final Answer:
To check and improve the site's performance and usability -> Option AQuick Check:
Lighthouse purpose = Performance & usability check [OK]
Hint: Lighthouse audits site quality, not code writing or deployment [OK]
Common Mistakes:
- Thinking Lighthouse writes code
- Confusing Lighthouse with deployment tools
- Assuming Lighthouse converts code formats
2. Which command correctly runs Lighthouse from the command line for the URL
https://example.com?easy
Solution
Step 1: Recall Lighthouse CLI syntax
The basic command to run Lighthouse is simplylighthousefollowed by the URL.Step 2: Match the correct syntax
lighthouse https://example.com matches the correct syntax:lighthouse https://example.com. Other options add unnecessary words or flags.Final Answer:
lighthouse https://example.com -> Option CQuick Check:
Correct CLI syntax = lighthouse URL [OK]
Hint: Use just 'lighthouse' plus URL to run audit [OK]
Common Mistakes:
- Adding extra words like 'run' or 'start'
- Using incorrect flags or options
- Confusing command order
3. After running Lighthouse on your Astro site, you see a low score in the 'Performance' category. What is the most likely cause?
medium
Solution
Step 1: Understand what affects Performance score
Performance issues usually come from slow loading resources like large images or heavy scripts.Step 2: Eliminate unrelated options
SEO metadata and favicon affect SEO or appearance, not performance. Number of Astro components alone doesn't cause low performance.Final Answer:
The site has large images and slow loading scripts -> Option DQuick Check:
Performance issues = large images or slow scripts [OK]
Hint: Performance drops mainly due to heavy resources [OK]
Common Mistakes:
- Confusing SEO issues with performance
- Blaming Astro components count directly
- Ignoring resource sizes
4. You ran Lighthouse but the report shows no data and an error message. What is the most likely mistake?
medium
Solution
Step 1: Identify why Lighthouse shows no data
Lighthouse needs a live URL to audit. Running it on a local file without a server means no data can be fetched.Step 2: Check other options
Not specifying a URL would cause a command error, not a no data report. Astro installation or Node.js version do not directly cause this error.Final Answer:
You ran Lighthouse on a local file without a server -> Option BQuick Check:
Lighthouse needs live URL, not local file [OK]
Hint: Always run Lighthouse on a live server URL, not local files [OK]
Common Mistakes:
- Running Lighthouse on local files without server
- Ignoring error messages about URL
- Assuming Astro install affects Lighthouse
5. You want to improve your Astro site's Lighthouse performance score. Which combination of actions is best?
hard
Solution
Step 1: Identify actions that improve performance
Optimizing images reduces load time, lazy-loading defers offscreen content, and reducing JS size speeds up scripts.Step 2: Evaluate other options
Adding components or animations can slow performance. Removing all images is impractical. Disabling caching doesn't improve site speed.Final Answer:
Optimize images, lazy-load components, and reduce JavaScript size -> Option AQuick Check:
Best performance = optimize images + lazy-load + reduce JS [OK]
Hint: Focus on image size, lazy loading, and JS reduction [OK]
Common Mistakes:
- Thinking more components always help
- Removing images entirely
- Misunderstanding caching effects
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
