Deviopath › Next.js

Effective Route Revalidate

Medium · Caching

Layouts and pages can export **route segment config**:

``ts export const revalidate = 60; // re-generate at most every 60 seconds export const dynamic = "force-dynamic"; // render on every request ``

One URL is built from several segments (root layout, nested layouts, page), so Next.js combines them:

- The **lowest** revalidate among the layouts and page wins. A child cannot make its parent revalidate less often.

- revalidate = false (the default) means "cache forever", so it never lowers anything.

- A fetch with a lower next: { revalidate } also lowers the route's revalidate. 0 means the route is rendered dynamically.

- dynamic = "force-dynamic" anywhere makes the whole route dynamic, which counts as 0.

Write effectiveRevalidate(segments). Each segment (root layout first, page last) is { revalidate?, dynamic?, fetchRevalidates? }, where fetchRevalidates lists the next.revalidate values of that segment's fetches (number or false). Return the effective number of seconds, or false if nothing sets a number.

Next: How Will This fetch Be Cached?