Caching static files on static sites

I see an issue with static files (js and css) loading slowly on static site. The behaviour is reproducible even on the docs site https://docs.render.com/static-sites which I believe is also hosted on render.

Here’s what I know about the issue:

  • When I load a page a request to get a static asset is relatively slow (~300ms). It has 304 Not Modified status and cloudflare’s Cf-Cache-Status is DYNAMIC. On subsequent requests, the behaviour is the same
  • If I switch caching off in dev tools, the first request for the same static asset takes approximately the same amount of time, the response is 200 and Cf-Cache-Status still DYNAMIC. All subsequent responses however are much faster and have Cf-Cache-Status HIT (wether caching is on or off in the browser)
  • If the cache is switched on in the browser again, in 5 minutes, we are back to the old behaviour of slow loading and Cf-Cache-Status: DYNAMIC.

It looks like, when 5 minutes are over (s-maxage=300) Cloudflare doesn’t cache the files anymore and instead makes a roundtrip to the origin on every request. Does my analysis make sense or am I missing something? Can this be fixed somehow (other than setting Cache-Control: no-cache on all requests)?

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