0
0
NextJSframework~8 mins

Mocking data fetching in NextJS - Performance & Optimization

Choose your learning style9 modes available
Performance: Mocking data fetching
MEDIUM IMPACT
Mocking data fetching affects page load speed and interaction responsiveness by simulating network calls without real server delays.
Simulating data fetching during development
NextJS
export async function getServerSideProps() {
  const data = { id: 1, name: 'Mocked Item' };
  return { props: { data } };
}
Returns data immediately without network delay, speeding up page load and interaction.
📈 Performance Gainnon-blocking, zero network delay, faster INP
Simulating data fetching during development
NextJS
export async function getServerSideProps() {
  const res = await fetch('https://api.example.com/data');
  const data = await res.json();
  return { props: { data } };
}
This makes a real network request on every page load, slowing down development and testing.
📉 Performance Costblocks rendering for 200-500ms per request depending on network
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Real network fetch on each loadMinimal1 reflow after data arrivesModerate paint cost due to delayed content[X] Bad
Mocked data returned immediatelyMinimal1 reflow immediatelyLow paint cost with instant content[OK] Good
Rendering Pipeline
Mocking data fetching bypasses the network request stage, allowing the browser to receive data immediately and proceed with rendering faster.
Network Request
JavaScript Execution
Rendering
⚠️ BottleneckNetwork Request
Core Web Vital Affected
INP
Mocking data fetching affects page load speed and interaction responsiveness by simulating network calls without real server delays.
Optimization Tips
1Use mocked data to avoid network delays during development.
2Switch to real data fetching before production to ensure accuracy.
3Mocked data improves interaction responsiveness by eliminating fetch wait times.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of mocking data fetching in Next.js during development?
AIt reduces the bundle size by removing data fetching code.
BIt eliminates network latency, speeding up page load and interaction.
CIt improves SEO by preloading real data.
DIt decreases the number of DOM nodes rendered.
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page, and observe if data fetch requests are made or if data is served instantly.
What to look for: Presence of network requests and their timing; mocked data shows no network delay.