Menu

What Next.js actually sends in Cache-Control (and what Vercel changes)
📰

What Next.js actually sends in Cache-Control (and what Vercel changes)

DEV Community: nextjs·nocache.dev·about 4 hours ago
#hxDX8oLb
#devtonextjs#devto#dev#next#cache
Reading 0:00
15s threshold

Ask three people what Cache-Control a Next.js page sends and you'll get three answers. All three can be right. It depends on how the page is rendered, which router you use, and whether Vercel sits in front of it.

I ran a live check on nextjs.org today to have something concrete to look at. Here's how to read what came back, and what changes when you host Next.js yourself.

The baseline: two requests to nextjs.org

The homepage HTML (trimmed to the caching-related headers):

cache-control: public, max-age=0, must-revalidate x-vercel-cache: HIT age: 572 x-nextjs-prerender: 1 x-nextjs-stale-time: 300 vary: rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch

Enter fullscreen mode

Exit fullscreen mode

A JavaScript chunk from the same page:

cache-control: public,max-age=31536000,immutable x-vercel-cache: HIT age: 48724 etag: W/"_next/static/immutable/chunks/3-f__u1tgqe9w.js"

Enter fullscreen mode

Exit fullscreen mode

These two responses cover most of what you need to know.

1.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.