How can I properly cache same resource from multiple subdomains

Let’s say, I have a resource at https://www.mydomain/robots.txt or https://www.mydomain/ads.txt in the origin and the same resources are returned from its subdomains (lets say millions of it or virtually uncountable to understand the problem).

The resource at https://www.mydomain/robots.txt is cached in cloudflare and I want cloudflare to return that cached resources when robots/user access it via different subdomains (like: https://aaa.mydomain/robots.txt). Since the resource from each subdomain is treated as new, it will take few requests for individual subdomain to get cached and multi million requests for a millions of subdomains, all going to the origin server. Additionally, as the same resource is treated as seperate resource it will take lots of storage for the cache (matters if using Cache Reserve).

This issue could be resolved if Cloudflare were to permit the modification of the Host header on Transform Rules or enable the specification of cache IDs on Cache Rules. Unfortunately, these features are currently exclusive to the enterprise plan. However, I propose that they consider enabling this functionality for customers who have purchased Cache Reserve.

I’m currently subscribed to the Pro plan and am wondering if there’s a way to achieve this without upgrading to the enterprise plan, as it’s currently beyond my budget.

You could look into using a Worker that intercepts requests to the paths and responds with the file from the apex domain:

2 Likes