how to force all browsers to not store your site's cache?

1.5k views Asked by At

When you are in the development stage it's a bit embarrassing to constantly remind your clients to clear the cache or to ask them to "refresh the page a bunch of times."

Is there a setting that I, the developer, can set in nginx or as a meta tag in the HTML to force all browsers to stop caching my page?

2

There are 2 answers

1
cnst On BEST ANSWER

Theoretically, according to Difference between Pragma and Cache-control headers? and also http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32, the following may be sufficient, in nginx:

add_header  Cache-Control   no-cache;

In practice, you might have to specify some extra directives; it would seem like using the expires directive should be sufficient, which will automatically add the Cache-Control header as above, too:

expires -1;
0
Shahe On

Try setting these headers:

"Cache-control: no-store, no-cache, must-revalidate"
"Expires: Mon, 26 Jun 1997 05:00:00 GMT"
"Pragma: no-cache"
"Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"

This will prevent the browsers from cashing the pages.