JSON doesn't cache (even with explicit page rules)

Hey all, my site contains two json files that I’d like to cache.

Cache-control headers with the correct amount of time are set.
Page rules explicitly telling cloudflare to cache each json file have also been set.

Result (regardless of how long I wait or retry):
cf-cache-status: DYNAMIC

My current fix for this is simply changing the extension of the files to .js which cloudflare will automatically cache, and that works fine.

However I would like to be able to cache .json files if possible, I was using bunnycdn previously and this was never an issue. I’m sure its something trivial that I’ve just missed or overlooked.

Thanks for your help :slight_smile:

The URL? And post screenshots of your page rules and list of page rules.

Page Rules


Response for 'news.json’
image

Interestingly the manifest.json works perfectly, but as you can see I’ve set the Edge Cache TTL manually.
https://covid19info.live/news.json

Well, that is the intended behaviour. .json files are not cached by default. You’d need to explicitly configure this in your first rule.

So even setting the specific page rule won’t enable caching on a .json file? (without setting the cache time)

How can I get them to cache based on the cache-control? Or is that pay more money thing.

Rule #1 wont do much as it tells Cloudflare to ignore the query string when caching, however that extension wont be cached in the first place. You’d need to set it to “Cache Everything” instead.

1 Like

If you want to both cache everything and ignore query string you’d either need to be on a plan which allows a custom cache key or set a custom cache key using workers.

1 Like

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