Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I prevent my CGI results being cached by the browser?

browser cached CGI results
0
Posted

How can I prevent my CGI results being cached by the browser?

0

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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123