How can I prevent my CGI results being cached by the browser?
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.