ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developersโ€ข14mo agoโ€ข
21 replies
svend

Workers with static assets - asset caching?

I have set up a React Router v7 site with CF Workers. The setup uses the static assets function in wrangler.json ("assets" parameter), which uploads all static assets that are compiled and bundled with Vite. They are all fingerprinted, so I would like to have the Cache-Control header to for example Cache-Control: max-age=31536000, immutable.

However - when testing the setup, all static assets are on first load (empty cache) delivered with a response of 200 together with Cache-Control: public, max-age=0, must-revalidate - which my understanding is that Cloudflare tells the browser to not cache anything.

On next refresh, the browser sends with a If-None-Match: ETag header in the request - and Cloudflare responds with a 304, which causes the browser to use the in-memory version of the asset.

To me, this seems like the static assets are just being cached by "luck"? If the browser had not cached assets regardless of cache-control header, no static assets would be cached?

I also tried to set up a cache control rule on the domain on the URI path /assets/* to override the cache header for Edge TTL and Browser TTL to 1 year. Nothing changes in the Cache-Control header due to this.

Any suggestions on what I am doing wrong?

Cloudflare Dashboard reports 0.5%-3% of requests are being cached over past 1-30 days, so this worries me to not get "right" before launching the site to the public - a lot less than what I would expect for a site that will be 99% static.
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Static Assets Support in Workers
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
10mo ago
update request url with workers static assets
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
12mo ago
How to cache workers with static assets (beta)?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
14mo ago
How to update Workers Static Assets?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
12mo ago