Page 1 of 1

Stop page from caching in bootstrap PHP page

Posted: Sun Aug 17, 2014 7:24 am
by mursaleen
I'm working on php application which contains a refresh button. On clicking I want to reload the page and get fresh information from server for the table.

I have used php headers:

Code: Select all

  
    header("Expires: Tue, 01 Jan 2000 00: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");
As well as following meta tags

Code: Select all

    <meta http-equiv="expires" content="-1"/>
    <meta http-equiv="pragma" content="no-cache" />
to stop the page to cache.

And I'm using

Code: Select all

    location.reload(true);
to reload the page. Its working fine in Firefox. But no result in chrome and ie.

For this application I'm using bootstrap based theme.

Any help in this regard will be appreciated as I have done every thing I found out there.

Thanks!

Re: Stop page from caching in bootstrap PHP page

Posted: Sun Aug 17, 2014 9:26 pm
by requinix
Typically you don't have to do anything to prevent caching. Neither PHP nor your server will sending caching information unless told to.

So, "no result" means... it's cached? Does Chrome explicitly say (in the Network tab of the inspector thing) that it is retrieving the page "from cache"?

Re: Stop page from caching in bootstrap PHP page

Posted: Mon Aug 18, 2014 12:12 am
by mursaleen
Over there in status column on pressing refresh button I'm getting status "304 not modified" (for most of the stuff) else when pressing ctrl + F5 over there status is "200 OK" that is when new data is fetched from data base.

Is there any straight away method in network tab to see if its being cached or not or this is what you were asking?

Re: Stop page from caching in bootstrap PHP page

Posted: Mon Aug 18, 2014 1:51 am
by requinix
The 304 Not Modified is one way caching happens. For the one I was thinking you'd see (easily) a "from cache" message.

304 means the browser went to your server for information and the server said it was not modified. Your code is actually telling the browser to do its half, but the 304 is coming from the server and that's not in the code you posted. Quite rare to see it in code, actually.

Does your server have any sort of caching thing enabled? What happens if you add an

Code: Select all

echo time();
somewhere in your code, without modifying anything else?