07 / 08

Discuss Client-side Router Cache?

Next.js has an in-memory client-side router cache that stores the RSC payload of route segments, split by layouts, loading states, and pages. When a user navigates between routes, Next.js caches the visited route segments and prefetches the routes the user is likely to navigate to. This results in instant back/forward navigation, no full-page reload between navigations, and preservation of React state and browser state.

With the Router Cache:
  1. 1

    Layouts are cached and reused on navigation (partial rendering).

  2. 2

    Loading states are cached and reused on navigation for instant navigation.

  3. 3

    Pages are not cached by default, but are reused during browser backward and forward navigation. You can enable caching for page segments by using the experimental staleTimes config option.