Next.js provides powerful caching and revalidation mechanisms to improve performance, reduce server load, and ensure fresh data. These are especially important in the App Router where server-side rendering and static generation are heavily used.
By default, fetch() in Next.js caches requests for static generation.
Cached at build time for static pages.
Suitable for content that doesn’t change often.
next: { revalidate }Use Incremental Static Regeneration (ISR) to revalidate data at intervals.
Page regenerates in the background after specified seconds.
Combines the speed of static pages with freshness.
cache: 'no-store')Fetch fresh data on every request.
Always returns up-to-date data.
Ideal for dashboards, user-specific content, or real-time apps.
Forces rebuild on every request but still benefits from static caching when possible.
Set HTTP caching headers in API responses:
s-maxage: Cache on CDN/edge
stale-while-revalidate: Serve stale content while revalidating
| Strategy | Next.js Setting | Use Case |
|---|---|---|
| Static | Default fetch | Blog, landing pages |
| ISR | next: { revalidate: seconds } | Frequently updated content |
| Dynamic | cache: 'no-store' | Dashboards, user-specific pages |
| Edge caching | Cache-Control headers | API responses, CDNs |
Use ISR for pages that update often but not every second.
Use dynamic rendering for user-specific or sensitive data.
Combine server-side caching headers with Next.js revalidation.
Minimize unnecessary re-fetching for performance.
Caching and revalidation in Next.js help build fast, scalable, and fresh web applications. By understanding static, ISR, and dynamic caching, you can optimize both performance and user experience.
Take quizzes related to this topic and see where you stand!
Start Quiz Now