When will Cloudflare fully support stale-while-revalidate with asynchronous background revalidation?

Sadly Cloudflare still doesn’t properly support stale-while-revalidate (SWR).

The correct way for it to be implemented is for the client to always be served a cached object if it’s within the time set for SWR, and Cloudflare should fetch a fresh copy of the object from the server asynchronously if the object is stale.The only time a client should be served an object from the server is if the object in Cloudflare’s cache is older than the time set for SWR.

Cloudflare’s current implementation is: If an object is stale, it will not serve the stale object to the client while it asynchronously fetches an update to the cache. Instead it simply forces the client to wait for a fresh copy of the object from the server. If there is a second request made at the same time for the same object, that’s when it will serve the stale copy (so I’ve heard, I actually haven’t seen this happen yet).

The spec can be found here rfc5861 Fastly implemented this in 2014: https://www.fastly.com/blog/stale-while-revalidate-stale-if-error-available-today

There are a number of threads on the community going back over quite a few years asking for this. Some don’t even have any response from Cloudflare.

I’d like to hear the latest from Cloudflare:

  1. Will you be implementing stale-while-revalidate fully?
  2. If yes, is there a timeline?
  3. If no, why is that the case? What are the blockers?

Cloudflare states its mission as so:

Cloudflare is on a mission to help build a better Internet.

If we look at the SWR spec, we find this definition.

The stale-while-revalidate HTTP Cache-Control extension allows a cache to immediately return a stale response while it revalidates it in the background, thereby hiding latency (both in the network and on the server) from clients.

The part in bold I believe highlights why fully implementing this standard should be a priority for Cloudflare as it fits perfectly with the mission of the company. One of the main goals of any CDN is to reduce latency for clients, I’m struggling to understand why this feature hasn’t been adopted yet.

1 Like

Cloudflare believes that they already do support SWR, but they’re just wrong, and they have no plans to learn more about this. (I expect no reply from Cloudflare on this thread.)

The “blocker” is purely a confusion on Cloudflare’s part. They think they already support SWR, and that the behavior you and I expect is not required by the SWR specification. @cscharff explains Cloudflare’s position here:

Which is to say, under the SWR spec, the cache MAY serve stale responses up to the indicated number of seconds, but they don’t, so, they’re “compliant” with the SWR spec by simply not doing SWR.

I explained what was wrong with Cloudflare’s statement three years ago. There was no reply. Most of the threads you linked above have no reply, either, or no reply to the clarification showing that, indeed, they really are wrong here. Cloudflare wrongly believes that there’s nothing further to discuss.

As you can see, a handful of nerds nagging them in half a dozen threads over three years hasn’t helped, and it isn’t going to help this time, either.

The only way this gets better is if large, high-value Cloudflare customers raise this issue with Cloudflare, and perhaps not even then, because they literally do not understand that they’ve failed to implement SWR.

Worst of all, if you do need SWR, it is technically possible on Cloudflare by re-implementing it yourself in a “Cloudflare worker” service worker, at extra cost to you. Implementing SWR correctly would cost Cloudflare money!

As Upton Sinclair wrote, “It is difficult to get a man to understand something when his salary depends on his not understanding it.” Thanks to Cloudflare Workers, Cloudflare is now that guy.

P.S. Fastly’s SWR support works great!

1 Like

P.S. Fastly’s SWR support works great!

Coincidence or not, Mark Nottingham, the author of RFC5861, works at Fastly. I think this says A LOT about Cloudflare.

I’ll start checking Fastly now as SWR is one of the most important features for me.