WPCOM-Legacy-Redirector
WPCOM-Legacy-Redirector copied to clipboard
Adding max-age to redirects
301s are cached by browsers (at least Firefox and Chrome) with no expiry date. This poses a problem when we need to update redirects in some cases.
I suggest adding a header like Cache-Control: max-age=
We may think of setting up a default behaviour and some configurable params.
Should this only be for 301, and not 302?
On my local test system, I'm seeing:
Cache-Control: no-cache, must-revalidate, max-age=0
On a VIP test site, I'm seeing:
cache-control: max-age=300, must-revalidate
Thought - if the redirect has only been added in the last 24 hours, make it max-age=60 or something really small.
If the redirect was added longer ago than 24 hours, make it a max-age={a day}.
These two values would be filterable.
The idea being that someone may add an incorrect redirect, and end up having to wait a day or force clear their cache before being able to confirm it has been fixed.
You'll also have to be sure to avoid creating additional cache-control: headers as one could be set already.
These redirects also are cached by their max-age, respecting the TTL, upstream via proxies such as Nginx, Varnish, CDN's, etc.
For VIP, the docs say:
Redirects with a 302 HTTP Status are cached for 1 minute, redirects with a 301 HTTP Status are cached for 30 minutes.