vercel / vercel/next.js

Missing `Cache-Control` header in `/404` rewrite response

Open
#76,168 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Linking and Navigating
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/nextjs-404-missing-cache-control-xvggzv

To Reproduce
  1. Go to terminal
  2. Stop Dev server
  3. Start Next in production mode: npm run build && npm start
  4. Execute curl -I http://localhost:3000/example
Current vs. Expected behavior

Current behavior

The response doesn't include a Cache-Control header:

Image

Expected behavior

The reponse should include an explicit Cache-Control header. I propose private, no-cache, no-store, max-age=0, must-revalidate to avoid caching.

Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4242
  Available CPU cores: 2
Binaries:
  Node: 20.12.0
  npm: 10.5.0
  Yarn: 1.22.19
  pnpm: 8.15.6
Relevant Packages:
  next: 15.1.7 // Latest available version is detected (15.1.7).
  eslint-config-next: 15.0.4
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next build (local), next start (local), Other (Deployed)

Additional context

I tested this behavior in Next v14 and v15.

My original motivation for rewriting a path to /404 was rewriting non-existing /_next/static URLs because for those we skip the middleware and they caused 500 errors in my page.tsx.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction, then run the reported npm run build && npm start flow and curl -I http://localhost:3000/example to inspect the /404 rewrite response. Trace the production handling of that rewrite and verify that the response includes an explicit Cache-Control header with the proposed no-cache behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.