Missing `Cache-Control` header in `/404` rewrite response
Nobody has claimed this yet.
- 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
- Go to terminal
- Stop Dev server
- Start Next in production mode:
npm run build && npm start - Execute
curl -I http://localhost:3000/example
Current vs. Expected behavior
Current behavior
The response doesn't include a Cache-Control header:
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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