View Full Version : Non-Cacheable web pages
Mirfus
04-20-2003, 10:59 AM
Errm, as a follow up to a previous thread which seems to be dead I'd reallylike to know how to make my index page non-cacheable. I've searched around and I've not found enough comprehensive information to help me bu I'm sure one of you guys who reads this must know something!
Thanks
Mirf :thumbsup:
pardicity3
04-20-2003, 05:52 PM
Whilst searching for "cache meta" (wierd search I know, but tag was too short...stupid 4 letter limit) I found this solution. It does recquire php which means it may not work for you if your host doesn't give you php, but hopefully it will suite you well.
Originally posted by brothercake:
<?
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
I also read up on the meta tag methods of disallowing chaching, but it seems to be the majority decision that this method is not widely supported at all. Looks like serverside may be your only choice.
Spookster
04-20-2003, 06:53 PM
http://www.sitepoint.com/article/956/3
zoobie
04-20-2003, 08:03 PM
...or you could use a little javascript to "timeout' and refresh...but personally, I don't like to bloat code and would use that meta tag if need be. :D
Mirfus
04-20-2003, 08:11 PM
I don't think I can use the Meta tag wot-not (something to do with AOL caching files independantly) but thanks all the same.
I will try the PHP attack... Do I need to insert that code into the HTML for the page or make a new database entry? If the latter - just how would I go about that and linking it to the page?
Thanks for helping - all of you. (Keep it up)
zoobie
04-20-2003, 08:20 PM
Try it at the top...with your html underdneath.
Here's the javascript equiv:
This is set for half a second...Use 1000 for one sec, 5000 for 5 seconds, etc.
<script>
window.onload = function() {
if (!window.location.search) {
setTimeout("window.location+='?refreshed';", .5);
}
}
</script>
It will blink as it's refreshing...:D
Spookster
04-20-2003, 08:32 PM
Originally posted by Mirfus
I don't think I can use the Meta tag wot-not (something to do with AOL caching files independantly) but thanks all the same.
I will try the PHP attack... Do I need to insert that code into the HTML for the page or make a new database entry? If the latter - just how would I go about that and linking it to the page?
Thanks for helping - all of you. (Keep it up)
I will assume you didn't read all of it or did not completely understand what you read so I will quote the pertinent sections here:
Expiration
If you want to have your page "expire," here's how to set it:
<META HTTP-EQUIV="expires" CONTENT=
"thu, 31 DEC 2002 00:04:00 EST">
What this means in the real world is that your visitors' browsers will use the cached version of your page, if available, until the specified date and time are reached, at which time the page will reload from the server the next time it's visited. To force your visitors' browsers to reload your page from the server (i.e. always use the most recent content) on every visit, use the following:
<META HTTP-EQUIV="expires" CONTENT="0">
META Cache-Control
This tag keeps your page from being automatically cached by servers or browsers. AOL, for example, usually stores cached pages on its servers, which means that AOL users may view cached (i.e. old) copies of pages without being able to see the updated versions. Although caching pages speeds loading times, if your page is updated frequently, I suggest you use the no-cache tag to make sure your visitors always get the most recent version of your page:
<META HTTP-EQUIV="Cache-Control" CONTENT ="no-cache">
The following tag works specifically on Netscape browsers:
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
brothercake
04-20-2003, 10:35 PM
Originally posted by Mirfus
I don't think I can use the Meta tag wot-not (something to do with AOL caching files independantly) but thanks all the same.
This is absolutely right - AOL users come through a public proxy server, and proxy servers don't actually read the page, so META tags make no difference. The same applies for anyone who surfs through a LAN proxy, and implies that, for all practical purposes, META no-cache tags are useless.
The reliable way to make a page non-caching (apart from having URLs with unique query-strings) is to do it server-side - serve the page with an expiry date in the past.
Spookster
04-20-2003, 11:16 PM
Originally posted by brothercake
This is absolutely right - AOL users come through a public proxy server, and proxy servers don't actually read the page, so META tags make no difference. The same applies for anyone who surfs through a LAN proxy, and implies that, for all practical purposes, META no-cache tags are useless.
The reliable way to make a page non-caching (apart from having URLs with unique query-strings) is to do it server-side - serve the page with an expiry date in the past.
They are useless unless you have your server set up to output an appropriate HTTP header according to the meta tag that is in the page.
Quote from AOL in reference to its proxy servers:
Your server must be configured to interpret the META tag and include the appropriate headers in it's response.
I agree the easiest way would be to use a server-side language.
Hoever if the person does not currently use a server-side language in their site or does not have that capability then to use a server side language such as PHP or ASP or whatever is out of the question.
Not to mention they would have to convert their files over to use .php or .asp etc extension unless of course they use .htaccess to have every html page parsed as .php files and I don't even know if their is that option on IIS with .asp.
Using a server-language is not THE only option for setting up pages to not be cached.
I believe you can also do this via .htaccess if I am not mistaken.
brothercake
04-21-2003, 12:45 AM
Originally posted by Spookster
They are useless unless you have your server set up to output an appropriate HTTP header according to the meta tag that is in the page.
So you have so set your server to read META tags and generate the appropriate headers? How is that possible - once the META tag is reached in the source, the document headers have already been sent :confused:
Spookster
04-21-2003, 01:17 AM
Originally posted by brothercake
So you have so set your server to read META tags and generate the appropriate headers? How is that possible - once the META tag is reached in the source, the document headers have already been sent :confused:
Not really sure but I would imagine your server would parse the page first, find the meta tag, output an appropriate header along with outputting the page.
About the easiest way to accomplish this is probably with .htaccess files.
ExpiresActive On
# This line required.
ExpiresDefault "access plus 1 day"
# Tells the browser to expire all pages in 1 day, unless defined below.
# You can even set this to seconds using: ExpiresDefault M604800
# Above seconds setting will expire the page in one week of seconds.
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/jpg "access plus 7 days"
# If your images rarely change consider setting this to more days.
<Files index.htm>
Header append Cache-Control "public, must-revalidate"
</Files>
# This ensures the browser loads the "latest" index.htm page for example.
An example I found. You can even specify just one particular page or all the pages in a directory and subdirectories or even just images if you like.
Oh and I believe you must have Apache 1.2 or higher with mod_headers or mod_expires installed. Not positive on it though.
Mirfus
04-21-2003, 09:05 AM
So, if I add this code to an .htaccess file inside /public_html then the 'frame.htm' will always be loaded anew?
ExpiresActive On
ExpiresDefault "access plus 1 day"
<Files frame.htm>
Header append Cache-Control "public, must re-validate"
</Files>
Do the .htaccess files already exist? I couldn't find one. I don't know much about working in the shell (I only ever used DOS - FreeBSD is something quite different). I created a new .htaccessfile (edit .htaccess) and typed in the code listed earlier in this post. However I have no had an Internal Server Error when trying to access frame.htm from the web browser.
I have removed the code from .htaccess for the moment.
What did I do wrong?
brothercake
04-21-2003, 03:43 PM
It's very unlikely your host has mod_expires enabled; most won't allow you to use it. Don't know why.
If you have your own server - well I don't think it's on by default; you'd need to go into httpd.conf and edit it to load the module
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.