1

Why do you usually need to disable the browser cache when sending requests via AJAX?

2 Answers 2

3

You don't have to, but it's for the same reason as any other browser cache disabling...you want to prevent the browser from using a previously fetched response...in other words you want the latest the server has to offer.

Usually cache headers from the server suffice, and you don't need to do much else, in other caes however...specifically, IE is the reason most of the time, it likes the cache the hell out of a response, requiring a query-string cache breaker to reliably get an non-cached response.

Sign up to request clarification or add additional context in comments.

1 Comment

You mean attaching something like "time=2011-17-4-12-30" to the requested URL to break the caching mechanisms? No other solutions? Thanks.
0

I wrote little bookmarklet which prevents AJAX cache. Try it. Let me know if it helped. http://marklets.com/Prevent+AJAX+from+being+cached.aspx

Text version: javascript:(function(){if%20(typeof%20jQuery%20==%20'undefined')%20{%20var%20jQ%20=%20document.createElement('script');%20jQ.type%20=%20'text/javascript';%20jQ.onload=runthis;%20jQ.src%20=%20'https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js';%20document.body.appendChild(jQ);%20}%20else%20{%20runBookmarklet();%20}%20%20%20function%20runBookmarklet()%20{%20$.ajaxSetup({cache:%20false});%20}})();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.