Since 301 and 308 redirects are intended to be permanent, it would be nice if Cloudflare could cache them, maybe not for eternity but for a while at least.
(Yes I know you can redirect on the Cloudflare side with Page Rules or Bulk Redirects so that the request never hits the origin, but in many cases I prefer to handle the redirects on my origin for various reasons)
Here’s the curious thing, if you look here: How long is a 302 redirect saved in browser? - Stack Overflow
It links to a page that apparently no longer exists but redirects to Default Cache Behavior · Cloudflare Cache (CDN) docs
The StackOverflow post implies that the following text used to exist:
If no cache headers are provided (no Cache-Control or Expires) and the url is cacheable (.jpg, .css, .js etc.) then CloudFlare caches both 301 and 302s. We cache 301 for a couple of hours and 302s for a shorter period of time (~20 minutes).
But if you search for that text, it doesn’t seem to exist anywhere.
However, some quick testing seems to indicate that the text is (still) accurate
It does seem that 301’s can be cached in some cases, but not 308’s. Why not?
Also choosing whether or not to cache redirects based on the file extension is really silly… it’s not a file, it’s a redirect, so why does the extension matter? Why not just cache it?
To try to highlight the weirdness of it, I confirmed the following:
test.html redirecting to test.jpg, the redirect is NOT cached
test.jpg redirecting to test.html, the redirect IS cached
It seems to only pay attention to the extension of the “redirect from” and not the extension of the “redirect to”
Any way to get more comprehensive caching of redirects?
I thought about doing something with “cache everything” page rules, but there’s apparently no way to make it only apply to redirects.