<!-- (c) 2005 HowToAdvice.com --> <!-- Site design and construction by Lonnie Lee Best --> <!-- Source: http://www.howtoadvice.com/StopCaching -->
While creating a web application that uses remote procedure calls, I ran into a problem; I would click a link that was suppose to update the content of a markup element (on the webpage), and instead of updating that element with the latest data from the web server, it would instead display a stagnant copy that the browser previously cached. This behavior occurred in the Internet Explorer 6.0 web browser, while the Firefox web browser worked as I expected.
Did you know that you that you can use multiple URLs to get to the exact same web resource? The following URLs, although different, go to the exact same web page:
If your remote procedure call needs to get:
Add an unprecedented key/value pair to the query string portion of the URL:
var url = "http://www.yourdomain.com/?id=47" + "&ms=" + new Date().getTime();
If your web application implements server side redirects be sure you understand what is going on during these redirects. When I first got done implementing the technique described in this article, I had a few partial page updates that were still being cached by Internet Explorer.
It turns out, that when my web application would implement a server side redirect (during a partial page update request), my web server would send the browser the URL of the redirected resource, and then (if it wanted to) the browser would make another request for the redirected URL. Since the redirected URL didn't have an unprecedented key/value pair, the browser served its cache rather than requesting the redirected URL from the server.
Rather than making the server-side redirect URLs unprecedented, I chose to implement a "server transfer", rather than a "request redirect". A "server transfer" doesn't tell the browser that you are sending it data from another web resource than the browser originally requested. It simply sends the redirected page to the browser without informing the browser that it has been redirected. If you use ASP.net, here's an article that describes the differences between these methods:
I'm sure PHP and others have equivalents to the .Net methods I've mentioned, so find out how your implementation handles it so that you can be sure to retrieve real-time data with your remote procedure calls.
Lonnie Best has been using the internet since 1993, and has been making web pages since 1995 - visit: http://www.lonniebest.com.