Skip to content

Instantly share code, notes, and snippets.

@danielstgt
Created February 4, 2022 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielstgt/82643186cbbc0a54591b18147adaf11e to your computer and use it in GitHub Desktop.
Save danielstgt/82643186cbbc0a54591b18147adaf11e to your computer and use it in GitHub Desktop.
Useful Redirect Headers

Useful Redirect Headers

Set a max age

Cache-Control: max-age=3600

The max-age=N response directive indicates that the response remains fresh until N seconds after the response is generated.

Indicates that caches can store this response and reuse it for subsequent requests while it's fresh.

Note that max-age is not the elapsed time since the response was received, but instead the elapsed time since the response was generated on the origin server. So if the other cache(s) — on the network route taken by the response — store it for 100 seconds (indicated using the Age response header field), the browser cache would deduct 100 seconds from its freshness lifetime.

Cache-Control: max-age=3600
Age: 100

Don't let the browser cache a redirect at all

Cache-Control: no-store

The no-store response directive indicates that any caches of any kind (private or shared) should not store this response.

Prevent the browser from storing a redirect permanently

Cache-Control: no-cache

The no-cache response directive indicates that the response can be stored in caches, but must be validated with the origin server before each reuse — even when the cache is disconnected from the origin server.

If you want caches to always check for content updates while reusing stored content, no-cache is the directive to use. It does this by requiring caches to revalidate each request with the origin server.

Note that no-cache does not mean "don't cache". no-cache allows caches to store a response, but requires them to revalidate it before reuse. If the sense of "don't cache" that you want is actually "don't store", then no-store is the directive to use.

Source: Mozilla MDN Cache-Control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment