PHP Ajax Caching for IE7 and iE8

I have an application written in PHP / Javascript that uses AJAX extensively. I am concerned that the default IE7 and IE8 caching behavior set for our organization to "Automatic" will cause my application to crash.

There are about 1500 users and my IT department says they will not change the caching setting in IE for all of these users.

My question is, how can I absolutely ensure that if I make changes to my application, all users will see the change immediately?

Also, how can I ensure that the AJAX always produces fresh results? Do I have to resort to making all my urls unique for every call?

Apparently, there is a certain amount of uncertainty in this topic on the Internet. There should be a definitive answer that always works.

Additional questions

Why doesn't just setting the HTTP headers in the AJAX files do the trick?

Also, how do I know if these solutions actually work? What is the correct procedure for testing caching behavior?

+2


source to share


5 answers


Try adding these headers:

header("Cache-Control: no-cache, must-revalidate");
header('Pragma: no-cache');

      



Also is it possible to pass rand number and / time () in the query string?

+1


source


If you are going to add a unique id cache to the end of each request then don't use rand. Use the current date / time (in ms) instead. This guarantees uniqueness, also more convenient for debugging.



+3


source


generating a unique URL is not a significant overhead. You just need to add a random number to the end of the url. In the case of GET requests, you can do it like this:

/someresource.php?some_key=foo&no_cache=9832742938642

      

You can simply ignore the rand key value pair in all script handling the request.

As far as I know, this is the only option you have.

0


source


Use a POST request instead, as the data on the server is obviously changing (otherwise you wouldn't have a caching problem). See http://javascript.about.com/od/ajax/a/ajaxgp.htm

0


source


With jQuery, you can add an extra parameter to avoid caching like this:

$.getJSON(myUrl, {"no_cache": new Date().getTime()}, function(data) {
// do something
}


$.getJSON(myUrl, {"no_cache": new Date().getTime()}, function(data) {
// do something else
}

      

0


source







All Articles