Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent cache 1

Status
Not open for further replies.

everytime

Programmer
Feb 21, 2001
31
0
0
GB
How can you stop a browser from cahing a page so that the lates version will be loaded each time. I have tried putting this in the head:

<META HTTP-EQUIV=&quot;Pragma&quot; CONTENT=&quot;no-cache&quot;>

but it didn't work. Thanks for any help
 
Hi,
Try:

<META http-EQUIV=&quot;Expires&quot; CONTENT=&quot;Mon, 04 Dec 1999 21:29:02 GMT&quot;>

You might not have much luck though - the whole expires/pragma support is, as I understand it, pretty lousy and inconsistent across browsers. :-(

Cheers and good luck,


Joe

 
hie
everytime, here is some ways 2 do it:
<META HTTP-EQUIV=&quot;expires&quot; CONTENT=&quot;-1&quot;>
<META http-equiv=&quot;Pragma&quot; content=&quot;no-cache&quot;>
<META http-equiv=&quot;Cache-Control&quot; content=&quot;no-cache&quot;>
<META HTTP-EQUIV=&quot;Expires&quot; CONTENT=&quot;Mon, 06 Jan 1990 00:00:01 GMT&quot;>
but looks like it wont work always-aldays..

here is what microsoft suggests 2 us 2 prevent files from cachin: have 2 head sections in the document:
<html>
<head>
<META HTTP-EQUIV=&quot;PRAGMA&quot; CONTENT=&quot;NO-CACHE&quot;>
<title>!!no cache</title>
</head>
<body bgcolor=&quot;#FFFFFF&quot;>
</body>
<head><META HTTP-EQUIV=&quot;PRAGMA&quot; CONTENT=&quot;NO-CACHE&quot;></head>
</html>
but it doesnt work for me too :-(


well, u might add current time or random number to the url, so, page wont be cachin..

<script>
var tmp=Math.floor(Math.random()*10);
top.location=&quot;mypage.html?&quot;+tmp
</script>

here is what i do 2 prevent some of my scripts from cachin:
<script language=&quot;javascript&quot;>
var time_now=new Date();
var secs=time_now.getSeconds()
document.write(&quot;<script language=\&quot;javascript\&quot; src=\&quot;scripptt.js&quot;+&quot;?time=&quot;+secs+&quot;\&quot;>&quot;+&quot;</&quot;+&quot;script>&quot;)
</script>
this wuld prevent those script from cachin, u can do the same with any url;

but
IE won't let you access a url when it's not part of your domain (it's a violation of security). - so, u can do that with ur urls only
regards, vic
 
The suggested trick using
<script language=&quot;javascript&quot;>
var time_now=new Date();
var secs=time_now.getSeconds()
document.write(&quot;<script language=\&quot;javascript\&quot; src=\&quot;scripptt.js&quot;+&quot;?time=&quot;+secs+&quot;\&quot;>&quot;+&quot;</&quot;+&quot;script>&quot;)
</script>

Does not alwayas work if placed in an asp environment. Also, with Netscape browsers, it may give you a run time error. This is surprising since asp is client-side independent. Any one know a possible explanation?
 
I use the following with my ASP application.

At the top of every page I have the following.

<%
Response.Expires = 1
Response.CacheControl = &quot;Private&quot;
dim uUrl
uUrl = &quot;uUrl=&quot; & Date & Timer
%>

Then for every url link I have in that document I do something like this.

<a href=&quot;somepage.asp?<%=uUrl%>&quot;>

Or if you already have some key/value pairs in the url it would look something like this.

<a href=&quot;somepage.asp?ID=1&Search=NYMX&<%=uUrl%>&quot;>


When you view source, you would see something like this.

<a href=&quot;somepage.asp?uUrl=9/22/200161368.09&quot;>

OR

<a href=&quot;somepage.asp?ID=1&Search=NYMX&uUrl=9/22/200161368.09&quot;>

That will force browsers to get an updated page for every link that is formatted like that.

The code ..

<%
Response.Expires = 1
Response.CacheControl = &quot;Private&quot;
%>

Sends additional headers for the page to further help prevent caching.

Good Luck

TW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top