Prompt
Why are transformed images not caching properly on my site?
Latest observation
Nov 3, 2026
OpenAI APIWeb search: off
Transformed images usually fail to cache properly for one of a few common reasons:
-
The transform URL changes every request
- If the image URL includes dynamic query params, timestamps, random tokens, or user-specific values, caches see each request as a different asset.
- Example:
/image.jpg?width=800&t=1699999999won’t cache well becausetchanges.
-
Cache headers aren’t set correctly
- The origin or CDN may be sending:
Cache-Control: no-storeCache-Control: no-cacheCache-Control: private- very short
max-age
- For transformed assets, you generally want something like:
Cache-Control: public, max-age=31536000, immutablefor versioned assets
- If the image is generated dynamically, ensure it still returns cache-friendly headers.
- The origin or CDN may be sending:
-
The transformation is considered unique each time
- Some systems cache transformed images by the exact combination of:
- source image
- resize/crop/format/quality parameters
- request host/path
- Even small differences like
format=webpvsformat=auto, or different parameter order in some systems, can produce cache misses.
- Some systems cache transformed images by the exact combination of:
-
Missing CDN/proxy caching
- The browser may cache, but your CDN or reverse proxy might not.
- If the response doesn’t include
ETag,Last-Modified, or cache-control directives that allow edge caching, transformed images may be regenerated on every request.
-
Cookies or auth headers are preventing shared caching
- If the image responses are tied to authenticated sessions or the server sets
Set-Cookie, many CDNs won’t cache them by default. - Any
Varyheader on headers likeCookie,Authorization, orUser-Agentcan also fragment the cache.
- If the image responses are tied to authenticated sessions or the server sets
-
Cache key configuration is wrong
- Your CDN might not be including the right parts of the request in the cache key, or it may be including too many.
- If it includes unnecessary query params, the cache gets fragmented.
- If it excludes transformation params, it may serve the wrong version.
-
The transform is happening at the wrong layer
- If your app generates the transformed image on every request before the CDN sees it, the CDN may be caching the wrong response path or not caching at all.
- Best practice is often:
- origin generates once
- CDN caches transformed output
- browsers cache the CDN response
-
Response is marked as uncacheable by the platform
- Some frameworks or image optimization endpoints default to short-lived or private caching.
- For example, image optimization middleware may intentionally set conservative cache rules unless configured otherwise.
How to diagnose quickly
Check the transformed image response headers in DevTools or curl -I:
Cache-ControlAgeETagLast-ModifiedVarySet-Cookie- CDN-specific headers like
X-Cache,CF-Cache-Status,X-Served-By
Common fix pattern
- Make the transform URL stable
- Ensure cacheable response headers
- Avoid cookies on image responses
- Confirm CDN cache key includes only necessary transformation parameters
- Version images by filename or path instead of timestamp query strings
If you want, I can help you troubleshoot this more specifically if you share:
- your image URL format,
- response headers,
- and what platform/CDN you’re using (Cloudflare, Vercel, Next.js, Imgix, Cloudinary, etc.).