Hello,
Is it possible to determine if a response returned by $.ajax was served from the browser's cache or was fresh?
Thanks.
Hello,
Is it possible to determine if a response returned by $.ajax was served from the browser's cache or was fresh?
Thanks.
No, that's not possible. What you can do is to create a new URL every time (eg: by appending a random string to the URL, which is ignored by the script on the server), or by setting the response's cache headers appropriately.
See: http://www.mnot.net/cache_docs/#CACHE-CONTROL
You might want to set max-age
, no-store
, no-cache
, must-revalidate
or a combination of the previous.
You can use the following in jQuery to make sure it does not cache:
$.ajaxSetup({cache: false}});
Am not sure what you are looking to achieve.
If you really want to know if the data is stale, you can do something like: