Skip to content

Commit

Permalink
Add cache control header for prefetch empty responses (#54732)
Browse files Browse the repository at this point in the history
Fix #45301

If you deploy Next.js with in front Cloudflare, empty prefetch responses will be cached because there is no `cache-control` header and the extension is .json, Cloudflare considers these requests cacheable assets

If you want a test for this I would like to know if there is an existing one where I can add the header check
  • Loading branch information
remorses committed Aug 29, 2023
1 parent fc48fc8 commit 20d0595
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/next/src/server/base-server.ts
Expand Up @@ -1614,6 +1614,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
!(is404Page || pathname === '/_error')
) {
res.setHeader('x-middleware-skip', '1')
res.setHeader(
'cache-control',
'private, no-cache, no-store, max-age=0, must-revalidate'
)
res.body('{}').send()
return null
}
Expand Down

0 comments on commit 20d0595

Please sign in to comment.