IE loves to cache AjAX calls. If your JavaScript makes repeat calls to get new data, IE would not even bother to make that call and will just give your script a cached response. IE would not even honor no-cache
headers for my AJAX requests. A popular trick that I learned from a friend and this discussion thread was to use a dummy parameter that will always different for each AJAX call. For example:
var d = new Date(); var myURL = "http://myserver:myport/myapp/myaction?d="+ d.getDate() + d.getHours() + d.getMinutes() + d.getMilliseconds();
Or you can use a simple counter variable.
The “random parameter” is an old webmaster trick indeed. We used as well to fetch dynamically generated images and javascript.
Very simple but saved us from a lot of testing nightmare.
The only thing that I have found to work is the following (this is Java but the idea still applies):
response.setDateHeader( “Expires”, -1 );
response.setHeader( “Cache-Control”, “private” );
response.setHeader( “Last-Modified”, new Date().toString() );
response.setHeader( “Pragma”, “no-cache” );
response.setHeader( “Cache-Control”, “no-store, no-cache, must-revalidate” );
Hi John,
Thanks for sharing your tip.
Thanks.. I will try to solve my cache issue as you suggested.
I have used this tip couple of years ago. Not long time ago I was debugging a client’s PC for debugging, I noticed in IE temporary Internet folder thousands of same Ajax link with different dummy parameters. This greedy IE kept every click the user did cached.