Static data fetching means getting data at build time. The data is fetched once when the site is built, then saved as static files. This makes pages load very fast because no server work is needed when users visit.
Click to reveal answer
beginner
What does server-side data fetching mean in Astro?
Server-side data fetching means getting data when a user requests a page. The server fetches fresh data each time, then sends the page. This is good for data that changes often.
Click to reveal answer
beginner
Name one advantage of static data fetching.
Pages load very fast because data is already included in the built files. No waiting for server responses on each visit.
Click to reveal answer
beginner
Why might you choose server-side data fetching over static?
If your data changes often or depends on the user, server-side fetching gives fresh data every time the page loads.
Click to reveal answer
intermediate
How does Astro let you choose between static and server-side data fetching?
Astro uses special functions like getStaticPaths for static and server-only code for server-side fetching. You pick based on your data needs.
Click to reveal answer
When is static data fetched in Astro?
AOnly when the server restarts
BOn every user request
CAt build time
DWhen the user clicks a button
✗ Incorrect
Static data fetching happens once during the build process, so data is ready before users visit.
Which data fetching method gives the freshest data on each page load?
AStatic data fetching
BNone of the above
CClient-side data fetching
DServer-side data fetching
✗ Incorrect
Server-side fetching gets data when the page is requested, so it is always up to date.
What is a downside of server-side data fetching?
APages load slower because data is fetched on each request
BData is never updated
CIt only works for static sites
DIt cannot fetch data from APIs
✗ Incorrect
Fetching data on every request adds delay before the page shows.
Which Astro function is used for static data fetching?
AgetServerSideProps
BgetStaticPaths
CuseEffect
DfetchData
✗ Incorrect
getStaticPaths helps fetch data at build time for static pages.
If your site data rarely changes, which fetching method is best?
AStatic data fetching
BNo data fetching
CClient-side fetching
DServer-side data fetching
✗ Incorrect
Static fetching is best for rarely changing data because it makes pages fast and simple.
Explain the difference between static and server-side data fetching in Astro.
Think about when the data is fetched and how it affects page speed and freshness.
You got /4 concepts.
When would you choose server-side data fetching over static in a real website?
Consider websites like news or user dashboards.
You got /4 concepts.
Practice
(1/5)
1. What is the main difference between static data fetching and server-side data fetching in Astro?
easy
A. Both fetch data only once at build time.
B. Static fetching gets data on every request; server-side fetching gets data once at build time.
C. Both fetch data on every request.
D. Static fetching gets data once at build time; server-side fetching gets data on every request.
Solution
Step 1: Understand static data fetching
Static fetching means data is fetched once during the build process, so pages load very fast but data stays the same until next build.
Step 2: Understand server-side data fetching
Server-side fetching means data is fetched fresh on every user request, so content is always up-to-date but slower to load.
Final Answer:
Static fetching gets data once at build time; server-side fetching gets data on every request. -> Option D
Quick Check:
Static = build time, Server-side = request time [OK]
C. Return statement should use props instead of body
D. Function should be named getStaticProps
Solution
Step 1: Check the fetch and JSON parsing syntax
The code calls response.json without parentheses, which is a function and must be called as response.json().
Step 2: Validate other parts of the code
The fetch URL looks valid, returning body is correct for server-side, and function name GET is valid for server-side fetch in Astro.
Final Answer:
Missing parentheses after json method call -> Option A
Quick Check:
json() needs parentheses to execute [OK]
Hint: Call json() with parentheses to parse response [OK]
Common Mistakes:
Forgetting parentheses on json()
Confusing server-side and static function names
Using wrong return structure for server-side
5. You want to build a blog with Astro where posts rarely change. Which data fetching method should you use and why?
export async function getStaticPaths() { ... } or export async function GET()?
hard
A. Use GET to fetch posts on every request to ensure always fresh content.
B. Use getStaticPaths to fetch posts once at build time for faster load and stable content.
C. Use getStaticPaths but fetch data on every request inside it.
D. Use GET and cache the data manually to simulate static fetching.
Solution
Step 1: Understand blog content update frequency
Since posts rarely change, fetching once at build time is efficient and fast.
Step 2: Match fetching method to content needs
getStaticPaths fetches data once at build time, ideal for stable content. GET fetches on every request, unnecessary here.
Final Answer:
Use getStaticPaths to fetch posts once at build time for faster load and stable content. -> Option B
Quick Check:
Rarely changing data = static fetch [OK]
Hint: Rarely changing data? Use static fetch for speed [OK]
Common Mistakes:
Choosing server-side fetch for stable data
Mixing fetch methods incorrectly
Trying to fetch every request inside static method
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.