-
I am using To display them, I generate pre-signed URLs:
The We're doing this to reduce our Source Image usage on Vercel which has skyrocketed because of this issue. |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 6 replies
-
👋 👋 Did you find any solution? We are going through exactly the same issue. |
Beta Was this translation helpful? Give feedback.
-
Running into a similar issue, though in my case I'm trying to get the Image component to cache my images (which come from pre-signed URLs) beyond their expiry period. |
Beta Was this translation helpful? Give feedback.
-
I'm having the same problem here.. |
Beta Was this translation helpful? Give feedback.
-
I am having the same problem using CloudFront in front of S3. The images are not cached anymore because the image URLs contain query params apparently. |
Beta Was this translation helpful? Give feedback.
-
Any one has any idea on this? We are planning to implement our own cache with custom eviction policies based on browser APIs to handle this, which I hope was already provided... |
Beta Was this translation helpful? Give feedback.
-
I'm also facing this issue. My current workaround is to use a custom imageLoader that redirects to a serverless function which redirects to a resized image (and caches it without the hash or query string) - though this is far from ideal. |
Beta Was this translation helpful? Give feedback.
-
There is no browser magic here, but you can manipulate your S3 URLs so they look the same for a time: https://advancedweb.hu/cacheable-s3-signed-urls/ @frankdilo @manema @tasercake @hmartiins @lelabo-m @rexwangcc @camnewnham |
Beta Was this translation helpful? Give feedback.
-
I have the same issue! I am using Supabase however |
Beta Was this translation helpful? Give feedback.
-
I'm having the same issue here. I'm using a third party CMS whose images come from a S3 bucket and I would like to optimize my images without overexceeding my quotas. |
Beta Was this translation helpful? Give feedback.
-
You can now use module.exports = {
images: {
minimumCacheTTL: 60,
},
} And module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'example.com',
port: '',
pathname: '/account123/**',
search: '',
},
],
},
} |
Beta Was this translation helpful? Give feedback.
-
For future travelers: The solution we landed on was to proxy images through an api endpoint. When serving the page we rewrite all image urls to go through an api endpoint. We include cache key parameters in the query string, for example: const input = new URL(data.imageUrl);
const url = `/api/image${input.pathname}?some_id=${data.id}`;
data.imageUrl = url; Then have a handler in export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const url = getOriginalImageUrl(req.query.some_id)
const response = await fetch(url);
const contentType = response.headers.get("content-type");
if (contentType) {
res.setHeader("Content-Type", contentType);
}
const buffer = Buffer.from(await response.arrayBuffer());
res.send(buffer);
} |
Beta Was this translation helpful? Give feedback.
You can now use
minimumCacheTTL
to change thecache-control
:And
images.remotePatterns.search
to filter on query strings or disallow all: