Disable page cache

What script should I use to prevent a page from being cached?


Answer 1, authority 100%

Use appropriate HTTP headers.

<?php 
function ae_nocache() 
{
    header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
}
?>

Or try adding tags to the page:

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

Answer 2, authority 25%

One way is to use a random parameter in the address bar, for example, “http://myssite.com/index.php?r=123412341234“, here the r parameter has no meaning, but Due to the fact that it is different each time the page is loaded, browsers consider the address unique and load the page each time.


Answer 3, authority 25%

If the question is “Don’t hit the cache”, then the answer is:
the page will still be in the cache. Everything is always cached in the browser, headers are only responsible for how long the page is there. So physically any file always ends up in the cache.

And if the question is “Always request a new version from the server”, then a get parameter like http://example.com/file.xxx?timewill help. Where time is the time stamp in milliseconds, for example. A document with a get parameter is always considered dynamically generated, so if the parameter changes, the browser thinks it is a new document and always reloads it. But this logic can be broken by proxies that can discard get parameters, so it’s better to do something like CNC: http://example.com/file/time/, where time is again time in milliseconds.