Link to home
Start Free TrialLog in
Avatar of carlmc
carlmc

asked on

Good Old Caching

Same old story - I am trying to stop my html pages from caching and make it refresh everytime it opens.

I have tried the pragma, no cache META tags at the top head as well as again before the end html tag.

This does not work - certainly in my IE5 anyway.

I have tried the asp equivalent and that does not work either.

Any suggestions!! I'm totally stumped. There is nothing in IIS is there although I have tried everything.

Amazingly it doesn't even refresh after I empty the temporary cached info

Help!!!!
ASKER CERTIFIED SOLUTION
Avatar of Mark Franz
Mark Franz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You start with META tags in the HEAD of the page.
Not well supported by some browsers.

The first instructs no caching:
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">

The second is necessary because IE5 ignores the pragma:

<META HTTP-EQUIV="Expires" CONTENT="-1">
That expires the page as soon as it is born.

However that may still not work in IE because it it is in the head where
it has to be.  In some kind of twisted logic IE sees the META tags, but
because the page has not yet been loaded there is nothing to cache so it
ignores it. Then when the page is loaded, it caches it.  The solution
from Micro$oft is to duplicate the tags after the end of the body.  
However they have to be in the head so you end up with this silly looking,
but effective page setup:

<HTML>
<HEAD>
<TITLE>---</TITLE>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

all the other head stuff

</HEAD>
<BODY>

All the good stuff that makes the page worthwhile

</BODY>
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
</HTML>



For ASP if you  want the same non-cache effect, here's the header
information:
<% Response.CacheControl = "no-cache" %>>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>

I don't know if once does it for ASP or if you have to repeat
that as well.


And of course Netscrap always has to add a twist of its own.  Pages
with forms in Netscrap can be a problem especially for secure environments.

Netscape suggests the following JavaScript be used in the BODY tag
of all pages that should not be cached:
<body onLoad="if ('Navigator' == navigator.appName) document.forms[0].reset();">

With all of that there is still a small chance that there is still an
unreported bug or a fringe browser that will screw up but this should
be 99% effective.

Cd&
"I don't know if once does it for ASP or if you have to repeat that as well."

No, ASP is fine with the initial call, however each page that you want to expire needs to have the properties set.

Good form tip for Nestcape CD.
Avatar of mouatts
mouatts

Firstly the Microsoft article that MGFranz quoted is a bit misleading and actually contridicted by the associated article. (http://support.microsoft.com/default.aspx?scid=kb;en-us;Q234067)

Firstly some early varients of IE5 don't actually support HTTP 1.1 although the options say they are sending 1.1 they aren't they are still operating at 1.0.

Secondly and importantly IE4 & 5 DO NOT parse the header of an HTML document and process HTTP-EQUIV tags (with the exception of the refresh). These tags are processed by the server which then converts them into the appropriate http header message. However the server only does this for HTML files not ASP files. Consequently it doesn't matter how many of these META tags you put in a ASP file because nothing is looking at them.

Therefore for an ASP document you will always need to add the caching directives as MGFranz has demonstrated.

The implication by Microsoft that the no-cache pragma is only used for HTTPS is wrong. Sure IE might only use this but if there is a HTTP1.0 proxy in the chain and no no-cache pragma is sent, then the proxy will cache the page (any 1.1 messages will be ignored but passed on). Unless a valid expiration has also been added then subsequent refreshes are likely to grabbed the cached copy from the proxy.

Microsofts suggestion that expires-1 should be used is a little iffy as well. According to the standard the expires directive only works if there is a date header as well. Many servers don't send this out so if they have followed the spec (which I grant you is doubtful) it shouldn't work a lot of the time (I know IIS5 sends it out but I'm pretty sure IIS4 didn't)

There is another little wrinkle in that there is a bug present in IE5 at least that sometimes a page becomes corrupted in cache. Once this occurs the page will always come from the cache regardless of any caching directive or expirations. Significant on a server log because you can see people effectively jump pages (EG Page 1 leads to page 2 but no request of any type is ever made for Page 1). The only way that you will clear this is to clear the browser cache.

So far as Netcrap is concerned the big problem in cache terms is with non html files. All caching and expiring strategies don't work. I don't know about V6 I refuse to put the lump of sh*t on my machine.

Steve

Avatar of carlmc

ASKER

Thanks MGFranz, your asp code seems to work.
Also thanks mouatts for that explanation.