# The Full Route Cache

> Caching entire HTML pages at build time.

Subject: Next.js | Lesson 24 of 65 | 7 min read
Interactive lesson: https://codewithanimation.in/nextjs/full-route-cache
Previous: [The Data Cache](https://codewithanimation.in/nextjs/data-cache.md) | Next: [The Router Cache](https://codewithanimation.in/nextjs/router-cache.md)

## The ultimate performance optimization

The Full Route Cache is what makes Next.js so fast. Instead of executing your React Server Components and hitting your database every time a user visits a page, Next.js does all of that work *once* during the build process (`next build`).

It generates a static HTML file and a React Server Component (RSC) Payload, and caches them on a CDN. When a user requests the route, they instantly receive the static files.

## Static by default

By default, Next.js assumes every route is static. It will aggressively attempt to cache your entire application into the Full Route Cache during deployment.

If a route does not depend on personalized user data (like a marketing page or a blog post), serving it from the Full Route Cache is the absolute best practice for performance and server costs.

## Dynamic Opt-outs

However, a route cannot be statically cached if its content depends on the specific user making the request. If a route opts out of the Full Route Cache, it is 'Dynamically Rendered' at request-time.

Next.js automatically switches a route to Dynamic Rendering if it detects the use of a 'Dynamic Function'. These include reading `cookies()`, `headers()`, or accessing the `searchParams` prop.

## Common mistake: Accidental de-optimization

The most common mistake developers make is accidentally importing `cookies()` in a deeply nested Server Component. Because Next.js renders the entire route as a single tree, reading a cookie anywhere in that tree instantly de-optimizes the *entire route*, forcing it to render at request-time.

Similarly, if a route uses an uncached data fetch (like `cache: 'no-store'`), Next.js will assume the route must be dynamic and opt it out of the Full Route Cache.

## Tip: Route Segment Config

You don't have to rely entirely on Next.js's automatic heuristics. You can manually force a route to be static or dynamic using Route Segment Configs.

Simply add `export const dynamic = 'force-dynamic'` or `export const dynamic = 'force-static'` to the top of your `page.tsx` or `layout.tsx` file to explicitly dictate how the Full Route Cache behaves.

## Try it: Static vs Dynamic Timelines

Watch the auto-demo mapping the difference between a Statically Rendered route (which utilizes the Full Route Cache) and a Dynamically Rendered route (which executes at request-time).

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/full-route-cache

## Check yourself

### Question 1

Which of the following actions will automatically opt a route out of the Full Route Cache?

- A. Using a Client Component ('use client')
- B. Reading from the cookies() function
- C. Fetching data with { cache: 'force-cache' }
- D. Using the <Link> component

Correct answer: B

Dynamic Functions like `cookies()`, `headers()`, and `searchParams` require information that is only known at the exact moment a specific user makes a request, making build-time static generation impossible.

- Why not A: Client Components can still be pre-rendered into static HTML during the build.
- Why not C: This actually encourages static rendering, as the data is known at build time.
- Why not D: The <Link> component relies on the Full Route Cache to prefetch RSC payloads.

### Question 2

When is the Full Route Cache populated by default?

- A. When the first user visits the page
- B. During the `next build` process
- C. On every single incoming request
- D. When the browser downloads the JavaScript bundle

Correct answer: B

Next.js attempts to execute your server code and generate static HTML/RSC payloads during the build step, storing them in the Full Route Cache before your app is even deployed.

- Why not A: That is how On-Demand Revalidation works, but not the default Full Route Cache behavior.
- Why not C: If it populated on every request, it wouldn't be a cache—that is Dynamic Rendering.
- Why not D: The Full Route Cache is a server-side concept.

## Remember this

- The Full Route Cache stores the entire HTML and RSC payload of a route.
- It is populated at build time (`next build`).
- Next.js statically caches routes by default.
- Using `cookies()`, `headers()`, or `searchParams` opts the route out into Dynamic Rendering.
- Use `export const dynamic = 'force-static'` to manually override the framework.
