you wouldn’t be purging the image from the origin, when you resize an image, the original image is cached as well as the resized variants of that image. If you purge the original image from cache, the resized variants will be purged too. Refer to URL format · Cloudflare Image Optimization docs
I think perhaps the confusion is that all docs assume that CF DNS pointing to where the image is hosted.
So in your example, example.com is where the image is hosted and is also the domain managed by CF.
In my case, however, example.com is where CF DNS is set up, but the image is hosted on an S3 bucket at mybucketname.s3.us-east-1.amazonaws.com/hello/image/dog.jpg
I’ve seen the article about “Configuring an Amazon Web Services static site to use Cloudflare” [1] but in my case, I have an existing bucket and changing the bucket’s Resource attribute could mess up the current bucket behavior.
at a high level, you have some image hosted on s3, you must have a url that is behind Cloudflare that would go and fetch this image, correct? so something like example.com/hello/image/dog.jpg that would fetch from mybucketname.s3.us-east-1.amazonaws.com/hello/image/dog.jpg on a cache miss? Or are you using workers/cache api to get the image cached from your s3 bucket?
mybucketname.s3.us-east-1.amazonaws.com is an S3 bucket so i’m not sure what’s there to purge, do you mean delete the file ?
In any case, how would deleting the file affect CF cache ? By default CF caches the resized image for 300 sec - Cache-Control: max-age=300 - Which I am also struggling to understand how to increase…
So that means that even if I deleted the image from S3, it will still be there in CF cache for 300 sec later.
is an S3 bucket so i’m not sure what’s there to purge, do you mean delete the file ?
I mean in your cloudflare dashboard or via api, send a single file purge request for the url: “https://mybucketname…”. because when your worker send an image resizing request for that url, that url was also cached at cloudflare and the cache key contains that url as documented in How the Cache works · Cloudflare Workers docs. So you don’t need to touch your s3 bucket or delete anything from it, you only need to purge that url from cloudflare via api/UI
I tried it and purged the specific origin url like you said and it didn’t have any effect, at least not a visible one - I still see a “cahce hit” header for that resource:
I am guessing that the 120 seconds defined in Cache-Control: max-age=120 cache directive is not the same as the time CF caches the image on the edge (as reflected in CF-Cache-Status directive) ?