How can we do "check for new versions of the page"?

I have a web application. which uses AJAX (via jQuery). I noticed that some users make updates that should be automatically updated on the web page via $.get , but in some cases the update does not occur. I narrowed the problem down to

 A. A race condition or B. Caching 

I can not reproduce the problem in IE7 and FF7 browsers. I went to the user machine and asked for their parameter in "Check for new versions of the page: every visit" in IE7. The problem seems to have disappeared. So, I am sure that the problem is in this parameter, initially set to "Automatic".

Do other browsers support this “caching” (or, nevertheless, it technically translates)?

Any idea why IE7 is not smart enough to let AJAX $.get() requests not be cached when the code explicitly calls the server? I mean, is there a known bug or is it a "feature"?

Is it possible to disable it without turning over the client settings?

+4
source share
3 answers

I think I should go from comments to the answer.

The way to get jQuery to disable caching for you is covered in this question .

Yes, the cache of other browsers, I do not know of a single common browser that does not support caching. However, there are some differences in how users set their preferences for this.

I believe that caching should be considered a function because it just makes a request for receipt, although I honestly don't know if the standards are consistent with this behavior.

It cannot be disabled without changing the client’s settings, but the easiest way is to make sure that it doesn’t see the same URL twice, so it cannot cache it. This is actually what jQuery does internally if you set the cache parameter to false.

You can control caching via headers, but I don’t think that all browsers support this correctly. I believe that now the URL is never repeated, this is the only reliable cross-browser solution.

+4
source

You can set the Cache-Control HTTP header to no-cache. This will force the browser to always issue a request to the server. IE and every other browser handle HTTP requests coming from javascript just like any other request.

+2
source

If the query string is the same for your $.get() , then the same URL, the browser will return the cache, and it really is. If you want it to always get a new copy, add a dummy query string parameter with a timestamp to the URL in $.get() .

+1
source

Source: https://habr.com/ru/post/1380254/


All Articles