Pages and Strong ETags
Does Pages automatically generate strong ETags that we can configure as an Enterprise customer? We have a ton of ongoing cache issues related to weak ETags and CSP hashing where our app cannot be loaded by some users. We suspect it has to do with weak ETags being used rather than strong ETags.
I was reading through https://developers.cloudflare.com/cache/how-to/cache-rules/ which allows for strong ETags, but this implies that Cloudflare cache will respect Strong ETags served from the origin which for us is Cloudflare Pages. Hence the question if Cloudflare Pages will generate Strong ETags.
(Note that we are an enterprise customer)
Cache Rules (beta) · Cloudflare Cache (CDN) docs
Use Cache Rules to customize cache properties of your HTTP requests. For example, create a rule to specify how long to cache a resource in the …
22 Replies
Generally, you do not want to configure any additional caching over pages. It already handels caching for you. See https://developers.cloudflare.com/pages/platform/serving-pages/#caching-and-performance. Is there any specific reason you want to put additional caching over pages?
We generally have seen weak etags completely break our app
If it doesn’t serve Etags and a Cache Control max-age of 0, then it shouldn’t break anything, no?
we use the integrity attribute in our JS chunks so the hash sometimes doesn't match up which causes issues. (SRI needs byte for byte matching but the actual JS that is loaded is some cached version that matches a weak etag but fails on the actual hashing)
Does it work if there isn’t an ETag at all?
Because that is what CF Pages does by default
But we aren't generating any ETags on our end? It seems like Pages is doing it. I can try and see if there was some button in the Cloudflare dashboard that we pushed to turn on weak etags
I might be mistaken. Just to check, do you see ETags on https://www.goalastair.com?
Livin' on the Edge
A blog about the stuff I do. Some of it is fun, some of it is cool, but it is all me.
yup at the bottom
Wut
Odd
Ok, well then I guess you would have to override each manually? I don’t think there are any rules that generate strong ETag headers…
Oh wait
Cache Rules maybe?
Or is that only for respecting strong etags, not generating them…
so there is
yup exactly
i just want cf pages to generate strong ETags....
Yeah, so then I guess you can just pre-generate them, or have a function to do so.
Though, could also put this in #pages-feature-suggestions
but wouldn't the pages worker run before any other custom worker?
Not with Functions
ahh so something like this https://developers.cloudflare.com/pages/platform/functions/examples/cors-headers/ ?
Adding CORS headers · Cloudflare Pages docs
This example is a snippet from our Cloudflare Pages Template repo.
Yeah, so you would hardcode the strong etags ahead of time
yea so CI would have to calculate the etag ahead of time (could just use the same digest from SRI) and then upload the script to this function
oh damn we are going to get capped on usage so quickly
If you don’t have that many assets, you could handle it with _headers
It's hundreds of JS chunks
Ok, yeah that might not go well
we are on an enterprise plan. i'll see if we can swing something with the customer success team or with support
seems rather odd that SRI isn't well supported
Just an update for future viewers. The pages app itself generates strong ETags. The CDN side of things is what was downgrading from a strong ETag to a weak ETag
You can check this by curl’ing across your pages app domain and the main app domain. We can’t figure out why the CDN is downgrading to weak ETag even after following the support article for settings that force weak ETAg
Sorry for pinging after this long. Just to check, did you try this one?
Just tried again with my website, and it seems to be working...