I happily just discovered the Cache-Control rules stale-if-error and stale-while-revalidate. I came across an article on Cloudflare's site that says that those two directives are ignored if CF's Always Online feature is enabled, so I've gone ahead and disabled that. However, I'm confused by the following quote:

The stale-if-error directive is ignored if Always Online is enabled or if an explicit in-protocol directive is passed. Examples of explicit in-protocol directives include a no-store or no-cache cache directive, a must-revalidate cache-response-directive, or an applicable s-maxage or proxy-revalidate cache-response-directive.

We do use s-maxage. Does that mean that stale-if-error is always ignored? An example of something we have is this:

Cache-Control: max-age=3600, s-maxage=86400, stale-while-revalidate=3600, stale-if-error=604800, public

Given the above, when is s-maxage considered "applicable" to override stale-if-error?

This is something I’ve been wondering about too. The wording around “applicable” s-maxage overriding stale-if-error is kinda vague. From what I’ve seen, s-maxage just sets how long a shared cache (like a CDN or proxy) can consider the response fresh — so I think if the resource is still within s-maxage, then stale-if-error wouldn’t even kick in, right?

But yeah, if s-maxage expires and stale-if-error is set, I’d expect the CDN to serve the stale copy if there’s an error upstream… unless that’s what they mean by it being “overridden”? idk it’s definitely not super clear.

Would love if someone with real-world experience on this with Cloudflare could chime in — does CF actually respect stale-if-error once s-maxage has passed and Always Online is disabled?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.