Add cache control header for prefetch empty responses (#54732)
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
This commit is contained in:
parent
fc48fc8c4c
commit
20d05958ff
1 changed files with 4 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue