Google Answers Logo
View Question
 
Q: Prevent caching of web content ( Answered 4 out of 5 stars,   3 Comments )
Question  
Subject: Prevent caching of web content
Category: Computers > Internet
Asked by: lizardnation-ga
List Price: $5.00
Posted: 20 Jan 2003 17:19 PST
Expires: 19 Feb 2003 17:19 PST
Question ID: 146223
Hello,

I was wondering how to mark content as not to be cached by cache/proxy
servers so that they're always pulled fresh from the site.

I've faced the problem of new content not appearing on the site till a
lot of time goes by or I visit the http://domain.com instead of
http://www.domain.com URL of the same site because it's less likely to
be cached.

Any advice?

Request for Question Clarification by tar_heel_v-ga on 20 Jan 2003 17:26 PST
Hello, lizardnation..

Just to clarify, you want to be able to get completely refreshed
version of webpages that you visit as opposed to pulling from your
hard drive cache.  Is that correct?

Clarification of Question by lizardnation-ga on 20 Jan 2003 17:59 PST
Hello Tar_heel_v,

Actually, I'm playing the role of the web content provider and would
like to cause some/all content to be marked as not to be cached, some
how, so that it's always picked up from the server itself and changes
do show up immediately.

/Lizardnation
Answer  
Subject: Re: Prevent caching of web content
Answered By: tar_heel_v-ga on 20 Jan 2003 18:26 PST
Rated:4 out of 5 stars
 
lizardnation,

After reading your clarification, I understand what you are looking
for.  As stated by sycophant-ga, the question mark trailing the end of
your URL will fool most proxies from caching.  To disallow caching on
the client or browser side, you can add the following meta-tags into
your code:

<META HTTP-EQUIV="Expires" CONTENT="0">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> [<--May not work for IE
Users]
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">

Another option is force a refresh using:

<META http-equiv="Refresh" content="10; url=New-page.html">

Where you see new-page.html, be sure and use a fully qualified url,
ie, http://www.servername.com/index.html).  You can set the content
flag to "0" which will cause the content to refresh immediately.

These tricks or, a combination of them, should ensure that the
majority of your visitors see the most up-to-date version of your web
page.

Thanks for your question and if you need any additional clarification,
please let me know.

Regards,

-THV

Search Strategy:
prevent your web pages from being cached

References:
Creating a Web Page with MS Word
http://homepage.psy.utexas.edu/HomePage/Staff/Douglas/webinstruct.html#preventcache

META tags: What they are and how they work
http://tech.irt.org/articles/js187/

How to prevent your pages from being cached by the browser
http://www.msfrontpage.net/fp/htpreventcache.htm
lizardnation-ga rated this answer:4 out of 5 stars
Hello Tar_heel_v,

Thanks for the answer, it was rather well complemented by Sycophant's comments.

Comments  
Subject: Re: Prevent caching of web content
From: sycophant-ga on 20 Jan 2003 17:32 PST
 
One cheap trick that allows you to get clean content through many web
proxy servers is to add a ? to the end of the URL. This can convince
the proxy that you are passing a HTTP GET variables to the page, and
as a result it should not cache it, as it may be dynamically
generated.

So instead of "http://www.domain.com/" try "http://www.domain.com/?"
you can add the question mark to the end of any URL that doesn not
already contain one.

If you are actually the author of the pages in question, there are
many other techniques you can employ to avoid your content becoming
stale in proxy servers.

However, there is no way that always works, because many proxies are
badly configured and don't behave as they should.
Subject: Re: Prevent caching of web content
From: lizardnation-ga on 20 Jan 2003 18:03 PST
 
Hello Sycophant,

You've read my mind. ;-)

I would like to prevent some or all content from a web site that I
author to be cached.  I would like to be successful with the majority
of servers.

From what I understood from you, adding a fake question mark would do
it for most servers.  How do I protect those pages from being cached
on the client/browser side?

Any advice?

/Lizardnation
Subject: Re: Prevent caching of web content
From: sycophant-ga on 20 Jan 2003 18:39 PST
 
In addition to the things mentioned by tar_heel_v there are some
things you can do on a server-wide basis if have administrative
control of the server in question.

I will assume the HTTP server involved is Apache, because it is the
most popular, and the one I am most familiar with.

The following directive may be very helpful:
http://httpd.apache.org/docs/mod/mod_headers.html#header
Using the mod_headers Apache module you are able to add arbitary
headers on a server wide basis, or within a .htaccess file, or
<VirtualHost> definition, or even in a <File>, <Location> or
<Directory> block - allowing you to add Expire and No-Cache headers to
all outgoing pages, or only those matching certain criteria.

However, Apache goes one better even! There is a mod_expire, which
allows you to set complex expire times on outgoing pages:
http://httpd.apache.org/docs/mod/mod_expires.html

Using these directives, you can expire content a specific length of
time after it's last access, or even after it's filesystem
modification time.

If you are not the server administrator, fear not, directives from
both of these modules can be used within the user-specified .htaccess
files, however, this will probably require the co-operation of your
sysadmin.



Also, a not about one of the suggestions in the above answer - the
Refresh meta tag above will not always force a cache flush, it may
well just load the content from the browser cache, and even if that is
not the case, requests will pass, as normal, though any proxy servers.
Therefore it's not that useful on it's own without the Expires, Pragma
and Cache-Control headers.


Regards,
sycophant

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy