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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catch-22 regarding not caching on IE

Status
Not open for further replies.

OsakaWebbie

Programmer
Feb 11, 2003
628
JP
I have a periodic newsletter that I archive on my web site. I have a link (on the menu bar of all my pages) that points to a tiny html file that redirects the user immediately to whichever issue is the newest one (after they get there, I provide access to the rest of the back issues). The original version looked like this:
Code:
<html>
<head>
<title>Osaka Direct</title>
<meta http-equiv="REFRESH" content="0;url=od_0512.php" />
</head>
<body>
<p></p>
</body>
</html>
I have recently realized that I need to keep it from caching, or else even when I put a new issue up, any users who have used the link recently will still get taken to the previous issue. Based on advice found on the web, I added the following before the REFRESH line:
Code:
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
It works fine in Firefox, but not in IE. The rumored reason is that IE doesn't even consider whether to cache a page until the downloaded size reaches half of the 64kB buffer. The suggested solution is to add a second head tag at the end of the file with the no-cache command in it, but obviously that won't work for this, as this file is nowhere near 32kB; the caching happens only after it redirects and gets the newsletter content (and I don't think anything after the refresh command is processed anyway). It is apparently indexing the cached page as index.html, not od_0512.php, so changing the URL in the refresh command does not change which newsletter I see when coming from the menu link, unless I delete my cache first. I don't want to put the no-cache command in the newsletter file, because it's fine to be cached when requested by its real URL rather than through the redirect.

I also tried a different method of doing the redirect itself:
Code:
<script language="javascript"><!--
location.replace("od_0512.php")
//--></script>
I can see some advantages to that method, but it didn't solve the IE cache problem.

Any ideas about how I can get that little file (that becomes big after the redirect) to not cache? Or even better, to cache the resultant newsletter content under the real filename of the content rather than index.html? I'm also open to other ideas about how to set this up (other than a dummy file to redirect) - I used to name the most recent newsletter index.php and then rename it when the next one came in, but I think that confuses search engines.
 
Why not do the redirect server-side? That way, you avoid all the caching issues altogether.

You have PHP, so it should be fairly easy, I'd say. Ask in the PHP forum for more on this one.

If you must do this client-side, try also adding an "expires" meta tag:

Code:
<meta http-equiv="expires" content="Mon, 5 Jan 2004 11:00:00 GMT" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for the reply, Dan. The reason I haven't done it server-side is the same reason that I stopped naming the current issue index.php. When search engines index my site, the current issue at that time would get indexed as index.php, and then for months any surfer who searches on something in that page wouldn't find it because they are taken to whatever the newest version is. I hope the redirect method will result in the content being indexed by its permanent filename. With my current code (the Javascript version), I see the URL in the browser's address box change the the real filename - that's a good sign, right? [ponder]

As for the expires meta-tag, is the intent to have one more way browsers might recognize the intent to not cache (like the reason I have two versions of "no-cache") by using a date in the past? Or are you imagining me using a date that actually means something, like one month after I put out an issue? But still, I don't want the expires code in the newsletters themselves, and it's not likely to do any good in the redirect file, for the same reason that the others don't work - IE doesn't yet think there is enough content to bother caching, so it ignores the instructions.
 
That Article said:
APPLIES TO
• Microsoft Internet Explorer 4.01 Service Pack 1
• Microsoft Internet Explorer 4.01 Service Pack 1
• Microsoft Internet Explorer 4.0 128-Bit Edition
• Microsoft Internet Explorer 4.0 128-Bit Edition
• Microsoft Internet Explorer 3.02

Are your users really still using IE 4?

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hmm, I didn't notice that - other pages (e.g. on forums) that pointed to that Microsoft page as a reference did not mention it applying to only old versions, so I didn't think to peer at the fine print, especially since the description fit my symptoms perfectly. Anyway, I can assure you: if I have recently accessed my little redirecting file, and then edit the file to point to a different newsletter, my copy of IE6 will not send me to the correct place. Firefox will, so it's not my code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top