Solved

Good Old Caching

Posted on 2002-05-09
5
170 Views
Last Modified: 2010-04-09
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!!!!
0
Comment
Question by:carlmc
5 Comments
 
LVL 18

Accepted Solution

by:
mgfranz earned 100 total points
ID: 6998896
Using .asp pages;

<%'-- PAGES CACHING CONTROL --
  '-- Use the following script at the extreme beginning of the specific ASP pages

'-- Prevent caching at the proxy server
Response.CacheControl = "no-store" ' HTTP 1.1 Cache-Control header : prevent all caching of a particular Web resource
'Response.CacheControl = "no-cache" ' HTTP 1.1 Cache-Control header : prevent all caching of a particular Web resource
'Response.CacheControl="private" ' HTTP 1.1 Cache-Control header : prevent the caching at the proxy server
'' Response.CacheControl="public"     ' HTTP 1.1 Cache-Control header : enable caching at the proxy server

' Prevent clients from caching web pages :
' no-cache prevents caching only when used over a secure (https://) connection.
' Treated identically to Expires: -1 if used in a non-secure page.
Response.AddHeader "Pragma", "no-cache" ' (META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE")
'Response.AddHeader "cache-control", "no-store"
' Note the Web page may still be cached in the Temporary Internet Files folder.
' see http://support.microsoft.com/support/kb/articles/Q222/0/64.ASP for reasons & resolutions
 
'-- Set page expiration date
Response.Expires = -1 ' cached but marked as immediately expired. (META HTTP-EQUIV="Expires" CONTENT="-1")
''Response.ExpiresAbsolute = Now() -1
' However, the page remains in the disk cache ("Temporary Internet Files") and is used in appropriate situations
' without contacting the remote Web server, such as when the BACK and FORWARD buttons are used to access the navigation history
%>

HTML pages;

<META HTTP-EQUIV="expires" CONTENT="-1">

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6998934
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&
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6998950
"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.
0
 
LVL 11

Expert Comment

by:mouatts
ID: 7010291
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

0
 

Author Comment

by:carlmc
ID: 7010454
Thanks MGFranz, your asp code seems to work.
Also thanks mouatts for that explanation.

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now