Why Data Fetching Happens at Build Time in Astro
📖 Scenario: You are building a simple Astro website that shows a list of blog post titles fetched from a data source.To make the site fast and efficient, you will fetch the data at build time, so the page is ready to serve without waiting for data on each visit.
🎯 Goal: Create an Astro component that fetches blog post data at build time and displays the titles in a list.
📋 What You'll Learn
Create a variable called
posts with an array of blog post objects containing id and title.Add a configuration variable called
maxPosts to limit how many posts to show.Use a
const declaration with Astro.fetchContent() or a simulated data fetch to get posts at build time.Render the list of post titles inside an HTML
<ul> element.💡 Why This Matters
🌍 Real World
Websites often fetch data at build time to create fast, static pages that load instantly for users.
💼 Career
Understanding build time data fetching is key for frontend developers working with modern frameworks like Astro, Next.js, or Gatsby.
Progress0 / 4 steps