views:

52

answers:

2

TLDR IE is still caching my requests even with Math.random() included in the URL.


So I added math random onto the end of my url:

var MYKMLURL = 'http://' + host + 'data/pattern?key='+ Math.random();

I also added math random onto my function param:

window.setTimeout(RefreshPatternData, 1000, MYKMLLAYER);


           function RefreshPatternData(layer) {
               layer.loaded = false;
               layer.setVisibility(true);
               layer.refresh({ force: true, params: { 'key': Math.random()} });
               setTimeout(RefreshPatternData, 30000, MYKMLLAYER);
           }

So the request appears as http://host/data/pattern?key=35678652545 etc.

It changes everytime the request is made.

It works in Firefox & Chrome & Safari etc. But IE8 is still caching the data and not updating my layer.

Any ideas as to why this might be occuring?


So i added:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

Still is caching the data. Any further ideas?

+1  A: 

You could try the answers to this post:

http://stackoverflow.com/questions/2848945/prevent-ie-caching

Lauri Lehtinen
I had a search on SO didnt find that question Thanks for the link:)
Thqr
+1  A: 

I had a similar issue with IE and it caching AJAX requests. (Why, God, why would you cache an AJAX request?) Worked fine in everything else, but IE required coercing via HTTP headers to not cache the AJAX request.

I've long forgotten the URL, but see: http://greenash.net.au/thoughts/2006/03/an-ie-ajax-gotcha-page-caching/

Also, the HTTP headers that did it for me were:

Pragma: no-cache
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0

...which I quite honestly gleaned off a website somewhere.

Thanatos