Skip to content

Commit

Permalink
Fix immutable header on static image
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Jun 8, 2021
1 parent 3860ea6 commit 60925e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/next/next-server/server/image-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ export async function imageOptimizer(
const contentType = getContentType(extension)
const fsPath = join(hashDir, file)
if (now < expireAt) {
res.setHeader('Cache-Control', 'public, max-age=0, must-revalidate')
res.setHeader(
'Cache-Control',
isStatic
? 'public, max-age=315360000, immutable'
: 'public, max-age=0, must-revalidate'
)
if (sendEtagResponse(req, res, etag)) {
return { finished: true }
}
Expand Down
6 changes: 6 additions & 0 deletions test/integration/image-optimizer/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ function runTests({ w, isDev, domains }) {
expect(res.headers.get('cache-control')).toBe(
'public, max-age=315360000, immutable'
)

const res2 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
expect(res2.status).toBe(200)
expect(res2.headers.get('cache-control')).toBe(
'public, max-age=315360000, immutable'
)
}
})

Expand Down

0 comments on commit 60925e2

Please sign in to comment.