← Next.js learning path
Next.js · Module 4 of 10

Data fetching and caching

Fetch data on the server and control how it is cached.

📖 Key ideas

  1. Server components can be async: const data = await fetch(url).
  2. Fetch directly from databases in server code.
  3. Caching and revalidation control freshness: revalidate: 60.
  4. Dynamic data (cookies, headers) makes a route render per request.
  5. Show loading.tsx or <Suspense> while waiting.
💡 Real-life example: Revalidation is a shop restocking shelves every hour: customers get fast service and fairly fresh stock.
async componentServer component that awaits data
revalidateSeconds before cached data refreshes
Dynamic renderingRendered per request
SuspenseShows fallback while loading