View Full Version : updating temp files
mindbenderz
12-11-2008, 08:09 PM
Is there a tag that can be inserted into the <head> so at anytime a user visits a page, it automatically checks for a recent version and updated the temp files. that way the user isnt browsing the site with old files, or has to refresh a few times to make sure he has updated files. thanks in advance
Snookerman
12-11-2008, 11:03 PM
I think what you want is to stop the browser from caching you page. This can be done with a meta tag in the head section:
<meta http-equiv="PRAGMA" content="NO-CACHE">
Unfortunately this is not enough for IE since it caches in a different way. The solution (from Microsoft Support) is to add extra head tags between the </body> tag and the </html> tag where you insert the same code. The entire page should then look something like this:
<html>
<head>
<meta http-equiv="PRAGMA" content="NO-CACHE" />
<title>Untitled Document</title>
</head>
<body>Body content of the page
</body>
<head>
<meta http-equiv="PRAGMA" content="NO-CACHE" />
</head>
</html>
Of course, this will not validate because of the extra head tags. There might be other ways to do this, but I think this is the simplest one.
I forgot that IE5 doesn't accept PRAGMA so you need to use this to prevent IE5 users from caching your page:
<meta http-equiv="Expires" content="-1" />
That makes the page expire the moment it's created. The final code would then be:
<html>
<head>
<meta http-equiv="PRAGMA" content="NO-CACHE" />
<meta http-equiv="Expires" content="-1" />
<title>Untitled Document</title>
</head>
<body>Body content of the page
</body>
<head>
<meta http-equiv="PRAGMA" content="NO-CACHE" />
<meta http-equiv="Expires" content="-1" />
</head>
</html>
I'm not sure if you need this IE5 meta tag in the first head section but it's better to be safe.
What on Earth is with the two <head>s? You don't need two <head> sections, and any browser that requires this mess is horribly broken.
IE7 is out; IE5 isn't supported by Microsoft any more, and shouldn't be supported by developers either. It's a BRPOC, and mangling code to work around it is no longer worth the effort.
Disabling caching entirely wasn't actually the request, and should almost never be done. Rather, an E-Tag header in the HTTP response can be used to indicate when a page has been modified and should be re-downloaded. If your page is dynamic then you may wish to generate this manually; otherwise, your webserver should be configurable to generate it from the file content or mtime, thereby keeping it automatically updated.
Snookerman
12-12-2008, 07:37 AM
Yeah, I thought it was strange too, but that's what Microsoft and other articles on the net say:
http://support.microsoft.com/kb/222064 (http://support.microsoft.com/kb/222064)
http://support.microsoft.com/kb/234067/EN-US/ (http://support.microsoft.com/kb/234067/EN-US/)
http://www.zann-marketing.com/developer/20051018/stop-browser-caching-using-meta-tags.html (http://www.zann-marketing.com/developer/20051018/stop-browser-caching-using-meta-tags.html)
http://www.htmlgoodies.com/beyond/reference/article.php/3472881 (http://www.htmlgoodies.com/beyond/reference/article.php/3472881)
If the OP doesn't want to do this, they can do what they want, I'm just trying to help.
The second article mentions nothing about this. The first does, but it seems that the other two articles you have mentioned completely misunderstood it. The article notes only that the page will be saved to the cache, but it will not as such actually be cached.
According to that article, it goes something like this:IE starts downloaded the page, sees the <meta> tag, and looks for the page in the cache. Since this is the first time the page has been downloaded, it does not exist, and nothing happens. When IE reaches the 32KB limit, it saves the page to the cache, ignoring the previously-encountered <meta> tag. When the page is downloaded for the second time, within the first 32KB the <meta> tag is once again encountered, but this time there is a page in the cache. Since the <meta> tag tells IE to ignore it, IE deletes the cached page and continues to download. When it hits the 32KB limit, the page is once again saved to the cache.As you can see, this means that despite the presence of the page in the cache, it is never used: the page is deleted and re-downloaded each time. There is no need for the extra <head>, and unless the page is larger than 32KB (which very few pages, being plain text, are — that's 32768 characters in most encodings!) the article seems to suggest that no caching will occur anyway.
There appears to be no pressing reason to mangle one's page in this manner — even in the unlikely event that disabling caching is in fact necessary in this particular case.
Snookerman
12-13-2008, 09:28 AM
Yeah, I agree that the whole thing seems a bit dodgy, I just assumed it was correct since Microsoft support seemed to agree. The second article was about pragma not working in IE5, in case there are still people out there using that.
Like you said, maybe the OP doesn't even want this, maybe they could be more specific about what they want.
If this were an issue, a better idea would be to insert 32KB of some sort of padding in front of the <meta> tag.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.