Q17: How do you opt out of caching for dynamic routes?

To force dynamic, real-time rendering on every request:

  1. Pass { cache: 'no-store' } or { next: { revalidate: 0 } } to fetch().
  2. Export route segment configs: export const dynamic = 'force-dynamic'.
  3. Use dynamic functions like cookies(), headers(), or searchParams.
Force Dynamic Route Config
// app/live-feed/page.js
export const dynamic = 'force-dynamic'; // Bypasses Full Route Cache

export default async function LiveFeed() {
  const data = await fetch('https://api.com/feed').then(r => r.json());
  return <div>Live Items: {data.length}</div>;
}
💡 force-dynamic ensures the page renders on every incoming request on the server.
Key Takeaways
  • Calling cookies() or headers() automatically converts a static route to dynamic rendering.
  • export const dynamic = 'force-dynamic' forces SSR across the entire page.
Knowledge Check

What happens to a static page route when you call cookies() or headers() inside its Server Component?