0
0
Astroframework~8 mins

Static vs server-side data fetching in Astro - Performance Comparison

Choose your learning style9 modes available
Performance: Static vs server-side data fetching
HIGH IMPACT
This concept affects how fast the main content appears and how quickly the page responds to user interactions.
Fetching data for a blog post page
Astro
---
export const prerender = true;
const res = await fetch('https://api.example.com/posts/1');
const post = await res.json();
---

<article>{post.title}</article>
Data is fetched at build time, so the page is served instantly without waiting for API calls.
📈 Performance GainReduces LCP by 200-500ms and lowers server CPU usage.
Fetching data for a blog post page
Astro
---
export const prerender = false;
const res = await fetch('https://api.example.com/posts/1');
const post = await res.json();
---

<article>{post.title}</article>
Fetching data on every request delays page rendering and increases server load.
📉 Performance CostBlocks rendering until data arrives, increasing LCP by 200-500ms depending on API speed.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Static data fetchingMinimal - pre-built DOM0 on loadFast paint with ready HTML[OK] Good
Server-side data fetchingMinimal but delayed DOM creation0 on load but delayedPaint delayed until data arrives[X] Bad
Rendering Pipeline
Static data fetching pre-renders HTML with data, so the browser receives ready content. Server-side fetching waits for data during request, delaying HTML delivery.
HTML Generation
Network
First Paint
⚠️ BottleneckServer-side data fetching delays HTML generation, increasing time to first byte.
Core Web Vital Affected
LCP
This concept affects how fast the main content appears and how quickly the page responds to user interactions.
Optimization Tips
1Use static data fetching for content that changes rarely to speed up page load.
2Avoid server-side fetching if it causes noticeable delays in HTML delivery.
3Choose server-side fetching when data freshness is critical despite slower load.
Performance Quiz - 3 Questions
Test your performance knowledge
Which data fetching method usually results in faster initial page load?
AServer-side fetching on every request
BStatic data fetching at build time
CClient-side fetching after page load
DFetching data with a delay timer
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page, and observe the time to first byte (TTFB) and content download time.
What to look for: Long TTFB indicates server-side fetching delay; fast TTFB with immediate HTML means static fetching.