Caching remote images

I’ve read the Netlify’s post about caching content https://www.netlify.com/blog/2017/02/23/better-living-through-caching/ and some other blog posts about how to change the _headers file to set up cache for specific static assets.

What I would want is to set cache for images not stored in assets but from remote service like Pexels or Unsplash (with urls manually included in the img src tag). Not sure about how the _headers rule should look like.

@markusand Welcome to the Netlify community.

You should probably investigate something like Fastly.

I disagree with Greg on this one around adding another service to the mix, but regardless of what solution you use: TL;DR there is no way for Netlify to directly affect the caching on assets served from other services. This doesn’t matter if you use:

<img src=https://my-image-service.com/asset.png>

or if you proxy to them (cf https://docs.netlify.com/routing/redirects/rewrites-proxies/#proxy-to-another-service) through our service: we don’t & can’t change the caching settings they use.

THEY need to set the timeout on those images (and, if you proxy to them through us - we’ll respect the cache timeout they advertise using the Cache-Control http response header), to cache on our side!). Adding another provider like fastly into the mix isn’t an optimal solution in my not so humble opinion, though it could address your specific need.

I see. I’ll continue investigate. Thank you both for your responses.