📖 Scenario: You are building a simple Astro website for a local bakery. You want to make sure the site loads fast and performs well on all devices. To do this, you will set up a basic Astro page and then learn how to audit its performance using Lighthouse, a tool built into modern browsers.
🎯 Goal: Create a basic Astro page with bakery information, configure a Lighthouse performance audit, and understand how to interpret the audit results to improve your site.
📋 What You'll Learn
Create an Astro page with bakery details
Add a configuration variable for Lighthouse audit settings
Run Lighthouse audit programmatically or via browser DevTools
Add final tags or attributes to improve performance based on audit
💡 Why This Matters
🌍 Real World
Performance audits help websites load faster and provide better user experience, especially important for small businesses like bakeries to attract and keep customers.
💼 Career
Knowing how to use Lighthouse and improve web performance is a key skill for frontend developers and web designers.
Progress0 / 4 steps
1
Create the initial Astro page with bakery info
Create a new Astro component file named Bakery.astro. Inside it, create a basic HTML structure with a <main> tag containing an <h1> with the text "Sunshine Bakery" and a <p> with the text "Fresh bread and pastries every day.".
Astro
Hint
Use semantic HTML tags inside the Astro component to structure your content.
2
Add Lighthouse audit configuration variable
Inside the Bakery.astro file, add a const variable named lighthouseConfig and set it to an object with a property categories set to an array containing the string "performance".
Astro
Hint
This config will tell Lighthouse to focus on performance audits only.
3
Add script to run Lighthouse audit in browser DevTools
Add a <script> tag below the <main> tag. Inside it, write a comment // Run Lighthouse audit manually in browser DevTools for this page to remind yourself how to start the audit.
Astro
Hint
Lighthouse audits are usually run from browser DevTools, so this comment helps remember that.
4
Add loading="lazy" attribute to images for better performance
Add an <img> tag inside the <main> tag with src="/bread.jpg" and alt="Fresh bread". Add the attribute loading="lazy" to this image to improve page load performance.
Astro
Hint
Lazy loading images helps the page load faster by loading images only when needed.
Practice
(1/5)
1. What is the main purpose of using Lighthouse with an Astro site?
easy
A. To check and improve the site's performance and usability
B. To write new Astro components automatically
C. To deploy the Astro site to a server
D. To convert Astro code into plain HTML
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 A