Astro fetches data during the build process instead of at runtime. Why is this approach beneficial?
Think about when the page content is generated and how that affects speed and search engines.
Fetching data at build time means pages are pre-built with all needed data. This makes pages load faster and helps search engines see complete content.
Consider an Astro page that fetches data at runtime instead of build time. What is the likely effect on the page?
Think about when the data is requested and how that affects user experience.
Fetching data at runtime means the page waits for data before showing content, causing slower load times.
Which code snippet correctly fetches data at build time in an Astro component?
Astro uses special exported functions to fetch data at build time and return it for page rendering.
Option A shows the correct use of an exported async function named get that fetches data and returns it for static rendering in Astro.
Review the code below. Why does the data not appear on the page after build?
export default function Page() {
const data = fetch('https://api.example.com/data').then(res => res.json());
return <div>{data.title}</div>;
}Think about how JavaScript handles promises and rendering in components.
The fetch call returns a promise, but the component tries to render before the promise resolves, so data.title is undefined.
In Astro, when are build-time data fetching functions like getStaticPaths or get executed?
Consider the difference between build time and runtime in static site generation.
Astro runs these functions during the build step to create static pages with data baked in, so no server is needed at runtime.