Skip to main content

Should We Use a Custom Domain on R2 for CDN Caching?

I’m got the Cloudflare R2 Media Module working ok, media all in Cloudlare not in Media Library , but the media is being served via the default R2.dev subdomain, which makes it publicly accessible. From what I understand, this isn’t ideal for production due to rate limits and lack of CDN caching features.

Would setting up a custom domain (e.g., cdn.mysite.com) for the R2 bucket be a better solution? It seems like it could provide secure media storage while leveraging Cloudflare’s edge caching for improved performance.

If this is the recommended approach, could you provide instructions on how to set this up?

For anyone curious, you can also explore this with GPT by asking:
"Is it better to use R2.dev or a custom domain with Cloudflare’s caching for serving media, and why?"

Shahjahan Jewel

It does not make much difference, but we have a subdomain in the community connected with Cloudflare r2.
I would recommend using the subdomain because if you every need to change your asset location, you can easily do that without changing the URLs.

Manoj Sharma

Shahjahan JewelΒ so basically use sub-domain as a custom domain rather than is R2.dev?

Shahjahan Jewel

Manoj SharmaΒ Yes that what we are using. We use using: cdn.community.wpmanageninja.com

Manoj Sharma

Daniel Herrera

Great, thanks for clarifying! As far as I see, using a custom subdomain ensures the CDN version leverages Cloudflare’s cache and avoids being public, which is important.

Image Optimisation: one concern with the current R2 setup though, is that it doesn’t allow for image optimisation before uploading to the Cloudflare server. This can be an issue as users, especially those on mobile, often upload large images (easily over 2MB). Without optimisation, this can quickly inflate storage usage and affect performance.

For BuddyBoss, we’ve been using EWWW Image Optimiser along with the free WP Offload Media plugin to upload optimised images to Amazon S3’s free tier. Would it be possible to consider integrating or allowing an image optimisation tool before the upload? This would help a lot in keeping storage efficient and improving delivery speeds.

Thanks again for the great support!

Mat β€Ž

Daniel HerreraΒ adding related link I hope this answer says much for this case

FluentCommunity compress and resize and convert to webp before save to the R2 or Local storage

Mike Rads

I recently connected using the dev URL. My Cloudflare Zero Trust client actually rejected the URL and blocked it. I switched to the public URL and it works as expected.