Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which browsers have problems caching XMLHTTPRequest responses?

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.*

like image 331
thomasrutter Avatar asked Mar 24 '09 13:03

thomasrutter


People also ask

Does browser cache XHR?

XHR responses are cached automatically in the browser cache if your HTTP cache headers permit it.

Does browser cache AJAX requests?

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.

Does browser cache 400?

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.

Can Put response be cached?

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 (…)


1 Answers

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.

like image 131
Simon Lieschke Avatar answered Nov 11 '22 12:11

Simon Lieschke