Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z - Internet FAQ Archives

FAQ: Frequently Asked Questions about CGI Programming
Section - 3.21 How can I prevent my CGI results being cached by the browser?

( Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Business Photos and Profiles ]

Top Document: FAQ: Frequently Asked Questions about CGI Programming
Previous Document: 3.20 How can I stop my CGI script reading and writing files as "nobody"?
Next Document: 3.22 How can I control the default filename when downloading a file via CGI?
See reader questions & answers on this topic! - Help others by sharing your knowledge

Firstly, we need to debunk a myth.  People asking this question usually
add that they tried "Pragma: no-cache".  Whilst this is not actively
wrong, there is no requirement on browsers to take any notice of it,
and most of them don't.

The "Pragma: no-cache" header (now superseded by HTTP/1.1 Cache-Control)
is a directive to proxies.  The browser sends it with an HTTP request
to indicate that it wants the request to be dealt with by the original
server and will not accept a proxy's cached document (e.g. when you
use a reload button).  The server may send it to tell a proxy not to
cache the document.

Having said all that, a practical hack to get round cacheing is
to use a different URL for your CGI script each time it's called.
This can easily be accomplished by adding a unique identifier such
as current time in the QUERY_STRING or PATH_INFO.  The browser will
see a different URL, but the script can just ignore it.  Note that
this can be very inefficient, and should be avoided where possible.

User Contributions:

Comment about this article, ask questions, or add new information about this topic: