Enable custom "Cache-Control" header for remote images on next/image #35658
Replies: 4 comments 1 reply
-
I opened a pull request for this feature, it's just missing an example (if needed), because I decided to wait a feedback about this feature request before get everything done. |
Beta Was this translation helpful? Give feedback.
-
@balazsorban44 we already made a big thread on pull-request page. Should I resume a bit what we already told there, here on discussion page? |
Beta Was this translation helpful? Give feedback.
-
@pedrosodre Thanks for opening this discussion and the pull request, and (most especially) for the workaround. I have made a more detailed comment in the pull request. The behaviour you're asking for was (as I assume you realise) how Next worked prior to 12.1. I'm not sure why this was changed although I assume it relates to this comment in the release blog post: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Describe the feature you'd like to request
Today, when we use
next/image
component to optimize an image that cames from a remote location (like AWS S3 or a CDN), next always setCache-Control
header asmax-age=0, must-revalidate
. I understand this behavior, but if we put a CDN on our frontend project it nevers hits CDN cache, since origin asked to revalidate it.For that reason, would be great to be able to customize the
Cache-Control
header for remote images.Describe the solution you'd like
I've checked
image-optimizer
code and actually we just set a high value toCache-Control
when the image is static. Would be great to be able to customize this header for remote images onnext.config.js
file (when image is not static).Describe alternatives you've considered
To fix it right now with the resources we have, it was necessary to overwrite the
response.setHeader
method to force a new value toCache-Control
for/_next/image
path, as the example below:Beta Was this translation helpful? Give feedback.
All reactions