简体   繁体   中英

PHP Ajax Caching for IE7 and iE8

I have an application written in PHP/Javascript which uses AJAX extensively. I am concerned that the default caching behaviour for IE7 and IE8 set for our organisation, of 'Automatic' will scupper my application.

There are approximately 1500 users and my IT department say that they won't change the caching option in IE for all those users.

My question is: How can I absolutely guarantee that if I make a change to my application, that all users will immediately see that change?

Also, how can I guarantee that AJAX will always bring back fresh results? Do I really have to resort to making all my URLs unique for every call?

There seems to be a fair amount of uncertainty on this topic on the internet. There must be a definitive answer that always works.

More Questions

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

Also, how do I know that these solutions really work? What is the correct procedure for testing caching behaviour?

If you are going to append a cache busting unique id to the end of every query then don't use rand. Use the current date/time instead (in ms). That guarantees uniqueness, also more convenient to debug.

Try adding these headers:

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

Also maybe pass a rand number and or time() in the query string?

making the URL unique isn't a massive overhead. You simply 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 just ignore the rand key value pair in whatever script is processing the request.

As far as I know, that's the only option you have.

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

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM