Setting a custom cache-control on CF images

We’re experimenting with using CF images for an app that has regular repeat visitors. One challenge were running into is that all of the images served by CF (imagedelivery.net) have a cache-control with a max-age=14400 (4 hours). As a result, browsers aren’t caching images from day to day and its showing itself in our performance metrics. Is there any way to set a custom cache control with CF images?

Thank you,
tarek

I think @zaid is the person to answer that.

Seems be no reason not to serve them with max-age=(Two years), and add the immutable directive.

1 Like

I serve my images through a worker, so used this example https://developers.cloudflare.com/workers/examples/alter-headers to do
newResponse.headers.set("cache-control", "max-age=604800");

Thank you. Thus far, it looks like the solution provided by @daniel55 is the only solution. It seems somewhat odd though to have such a short max-age on images without the added complexity of using a worker. We’re currently A/B testing CF images vs another CDN solution with max-age=525600 and the load differences are apparent even to the naked eye. @zaid – Might you have some insights?

Also check out @Walshy example of CF Worker for own domain hosted CF Images Cloudflare Images Domain - #5 by Walshy, I’ve tested it and works nicely :smiley:

1 Like

This topic was automatically closed after 15 days. New replies are no longer allowed.