Do any of the currently popular browsers have particular problems caching* XMLHttpRequest responses that I need to be aware of?
I'd like to be able to include XMLHttpRequest queries on every page as a method of dynamically loading content (ie JSON) or behaviour (like eval()ed Javascript) relevant to the type of page, but wanted to make sure that the resources it receives from the server could be cached, if the server sent the right headers.
I was concerned to read this article which mentions that browsers such as Firefox 1.1 do not cache any content obtained via XMLHTTPRequest, and that it always requests new data is sent completely (with Cache-Control and no If-Modified-Since) regardless of headers sent by the server.
Obviously that article is very old - I don't even remember a Firefox 1.1; so what are the considerations I need to make for current popular browsers and is there any trick for when I specifically want responses to be cached?
**To clarify my question, by caching, I mean client-side caching, where the server issues freshness information (in the form of a Cache-Control: max-age directive or an Expires: header) and the browser stores a copy of the response in its cache along with an expiry date, so that future requests for the same resource issued from subsequent pages can be satisfied from the browser cache without the need for any contact with the server at all. All major browsers do this correctly for most content, but I've heard that Firefox cannot do this for XMLHttpRequest content. What I'm asking is if anyone knows of cases where any of the modern browsers do not cache responses according to the spec when using XMLHttpRequest.*
XHR responses are cached automatically in the browser cache if your HTTP cache headers permit it.
Fact #1 : Ajax Caching Is The Same As HTTP Caching At this level, the browser doesn't know or care about Ajax requests. It simply obeys the normal HTTP caching rules based on the response headers returned from the server. If you know about HTTP caching already, you can apply that knowledge to Ajax caching.
Clear browser cache or cookies As we examined, the browser cache is a very common cause of the “HTTP Error 400,” and it is mostly related to outdated or corrupt cached files and saved cookies. All browsers provide the option to clear their cache and cookies.
A PUT request cannot be cached. Moreover, it invalidates cached data for request to the same URI done via HEAD or GET : PUT /pageX. html HTTP/1.1 (…)
Mark Nottingham has an excellent set of functional tests that demonstrate browser XMLHttpRequest caching behaviour. Load up the page in the browsers you want to support and work out what techniques you can and cannot rely on to have your response cached.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With