What's the best way to force a browser NOT to cache a page?

liunx

Guest
Can someone tell me what's the best way to force a browser NOT to cache a page?<br />
<br />
And would any such method work on 95% of browsers?<br />
(If so... I'd be more than happy!)<br />
<br />
Any help would be appreciated.<br />
<br />
Thanks.<br />
<br />
<br />
Jam<!--content-->none. You can't force a browser ot do anything like that really. You can add a header or use a meta tag to tell the browser not to read from cache when it comes back, but there is no way to tell it not to cache the content, no-cache and all will not do it.<!--content-->The following headers do the job on most occasions:<br />
header("Content-type: text/javascript");<br />
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); <br />
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); <br />
header("Cache-Control: no-store, no-cache, must-revalidate"); <br />
header("Cache-Control: post-check=0, pre-check=0", false); <br />
header("Pragma: no-cache");<!--content-->Originally posted by Vladdy <br />
The following headers do the job on most occasions:<br />
header("Content-type: text/javascript");<br />
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); <br />
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); <br />
header("Cache-Control: no-store, no-cache, must-revalidate"); <br />
header("Cache-Control: post-check=0, pre-check=0", false); <br />
header("Pragma: no-cache"); <br />
<br />
And just so you know, jammer, that is php. And if you use it, you have to rename your file as whatever.php and those lines of code have be at the very top of your .php file inside of <?php ?> tags<!--content-->header("Content-type: text/javascript");<br />
whats the point of that one?<!--content-->Thanks for all the replies.<br />
How can I put the above code straight into HTML?<br />
Let me know.<br />
Thanks.<!--content-->Originally posted by The Cheat <br />
whats the point of that one? <br />
oops, I was copying it from a file returning javasript. Do not need that one for caching.....<!--content-->Why are you wanting a 'no-cache' solution?? If it's an attempt to keep your source/images/whatever from being stolen then you need to give up now. All a no-cache does is tell the browser to ignore what it has Download <!--more-->ed on a previous visit and use a fresh copy of what's on the server; it DOES NOT keep the browser from dowloading content. source/images/whatever HAVE to be Download <!--more-->ed; it's the only way the browser can show the page. :)<!--content-->Erm... well the problem is that I'm having trouble with my Flash files.<br />
<br />
What 'normally' work is if I change the name of the Flash file and make these changes in the HTML.<br />
<br />
When the HTML page is loaded, the new Flash movie is loaded and not the old one.<br />
<br />
But for some reason... when I'm making the changes to my HTML... the old page is being picked up - despite repeatedly refreshing AND going to 'internet options' and deleting stored files.<br />
<br />
Could it be that my ISP is causing the problem by caching on their servers?<br />
<br />
Whatever... surely... if I can figure out how to stop the browser caching... then this would solve my problems?<br />
<br />
Let me know what you think.<br />
<br />
Thanks.<br />
<br />
<br />
Jam<!--content-->Originally posted by Vladdy <br />
The following headers do the job on most occasions:<br />
header("Content-type: text/javascript");<br />
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); <br />
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); <br />
header("Cache-Control: no-store, no-cache, must-revalidate"); <br />
header("Cache-Control: post-check=0, pre-check=0", false); <br />
header("Pragma: no-cache"); <br />
I thought that just told the browser to recache it, i thought thats how the browser took it, whenever it visits it does not read from cache. Because I recall being able to look at sites with headers like that and the meta tags while off line. For these purposes it will make the browser use a fresh copy, but saying it does not cache it is not technically correct I believe... or atleast not with my browser.<!--content-->Originally posted by jammer20002 <br />
Thanks for all the replies.<br />
How can I put the above code straight into HTML?<br />
Let me know.<br />
Thanks. <br />
Those are HTTP headers so to put them literally into the HTML you would use the <meta http-equiv="" content=""> tag.<br />
<br />
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); becomes<br />
<meta http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT"><br />
<br />
header("Cache-Control: no-cache"); becomes<br />
<meta http-equiv="Cache-Control" content="no-cache"> <br />
<br />
header("Pragma: no-cache"); becomes<br />
<meta http-equiv="Pragma" content="no-cache"><!--content-->Thanks for all the replies.<!--content-->For Internet Explorer you can hold down the control key and hit the refresh button or cntrl-F5. F5 is the hot key to refresh the browser. I believe its Shift-Refresh for Netscape and Mozilla variants. This will tell the browser not to load from cache but go get the new page off the server.<!--content-->Originally posted by KarmaKills <br />
For Internet Explorer you can hold down the control key and hit the refresh button or cntrl-F5. F5 is the hot key to refresh the browser. I believe its Shift-Refresh for Netscape and Mozilla variants. This will tell the browser not to load from cache but go get the new page off the server. <br />
<br />
Well, that was one of the problems. I was doing this a million times - and it still didn't work!<br />
<br />
I then tried to delete all the temporary files stored - that didn't work either.<br />
<br />
Any suggestions/exaplantions of why the above occured?<br />
<br />
I'm not sure that the above code will work to solve the above problem, but I do need it for all the other work I do.<!--content-->i've heard of this a lot from people who make flash movies. I think the secret is to close the browser and reopen<!--content-->Tried that!<br />
The problem started off as a Flash one.<br />
But then... all I was left doing was making changes to a HTML file, with no Flash.<br />
I uploaded the new file and the version JUST WOULDN'T be picked up!<!--content-->I tripped across this thread while trying to find a solution for forcing html pages to be re-loaded from the server on every visit. I found this article on MS that finally did the trick:<br />
<br />
"Pragma: No-cache" Tag May Not Prevent Page from Being Cached:<br />
<!-- m --><a class="postlink" href="http://support.microsoft.com/kb/222064/">http://support.microsoft.com/kb/222064/</a><!-- m --><br />
<br />
- Chip<!--content-->
 
Back
Top