Custom domain on R2 bucket with image resizing - caching

So I’ve stumbled upon a problem where our images on our custom domains seem to not cache very long. Maybe for a couple of hours at max. I have a website with traffic but these images are resized every time they load and take 1.2s to load which gives a bad user experience and warnings on pagetools like google pagespeed etc.

  • images.customdomain. com is set as custom domain to R2 bucket called “maps”
  • Images are resized and loaded on the fly like this maps.customdomain. com/cdn-cgi/image/format=auto,width=500/maps/map1234.png
  • I have set a rule in Page rules where maps.customdomain. com/* should Cache Everything and Edge Cache TTL for one month.
  • I have set a Cache rule on maps.customdomain. com that should match host maps.customdomain. com and override Edge Cache TTL to 1 month.

But every morning when i load the images i get a cf-cache-status “MISS” in the headers. Also the analytics and logs says just like 1% on that domain are cached. Stuff from the origin (www.customdomain. com) server are also set “Cache everything” for one month and it works well with lots of “HIT”.

Response headers

Accept-Ranges: bytes
Cache-Control: max-age=14400
cf-bgj: imgq:85,h2pri
CF-Cache-Status: MISS
CF-Ray: 7c7a88f7cadcbe35-CPH
cf-resized: internal=ok/m q=0 n=559+263 c=0+0 v=2023.4.2 l=39624
Connection: keep-alive
Content-Length: 39624
content-security-policy: default-src 'none'; navigate-to 'none'; form-action 'none'
Content-Type: image/avif
Date: Mon, 15 May 2023 10:00:39 GMT
ETag: "cfcwcs600-GvXewUbjUJbzT7U_hi8yaH7pEf2-gNpVDQ:1e2d318cefb3be6e31ca6372c10333aa"
Last-Modified: Fri, 10 Feb 2023 04:49:29 GMT
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Report-To: {"endpoints":[{"url":"https:\/\/\/report\/v3?s=cjFUcn0eAE3ufBlA9KeMZbwn%2BYORg3rag8vq4Ki6hGfVFwivxrmLAYhQ%2F636vgwbf5gyg6DP9%2FcoyvSD1HKDWuJ3nHLKeDdnIyNT0PJ%2FXhVVWAwaikRf%2FEAd9XdBV%2F%2Btag9GNLyk2XU%3D"}],"group":"cf-nel","max_age":604800}
Server: cloudflare
Vary: Accept, Accept-Encoding
x-content-type-options: nosniff

So my questions is how do i set an Edge Cache 1 month for images(resized images) from the R2 bucket with a custom domain? I’m doing / understanding something wrong here…

(maps.customdomain. com is of course another domain)

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