For our Next.js 14 project with app router I have tried and failed to get caching to work. This is our first project with the app router, so that might have something to do with it.
We always get a x-vercel-cache: MISS so I tried to add cache instructions in next.config.mjs
On our local development machine we get Cache-Control: s-maxage=60, stale-while-revalidate=120
However, after deployment to Vercel this has changed to cache-control: private, no-cache, no-store, max-age=0, must-revalidate
and always gives us a x-vercel-cache: MISS
I am right in thinking that the s-maxage/stale-while-revalidate instruction to Vercel should be enough, or are there possibly other pitfalls in our code that prevents Vercel from caching the pages?
When you see x-vercel-cache: MISS, it means that Vercel’s edge network didn’t find the requested content in its cache and needs to be generated or fetched from the original source.
The change in Cache-Control headers suggests that something is overriding your intended caching behavior on Vercel. The headers you’re seeing on Vercel (private, no-cache, no-store, max-age=0, must-revalidate) are explicitly disabling caching.
In Next.js with the App Router, certain operations trigger dynamic rendering, which can prevent caching. These include:
Using dynamic functions like cookies(), headers(), or searchParams in your route handlers or page components .
Setting dynamic = 'force-dynamic' in your route segment config.