目前流行的浏览器是否存在缓存* XMLHttpRequest 响应的特殊问题,我需要注意这些问题?
Do any of the currently popular browsers have particular problems caching* XMLHttpRequest responses that I need to be aware of?
我希望能够在每个页面上包含 XMLHttpRequest 查询,作为动态加载与页面类型相关的内容(即 JSON)或行为(如 eval()ed Javascript)的方法,但想确保如果服务器发送了正确的标头,它从服务器接收的资源可以被缓存.
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.
我担心阅读 这篇文章Firefox 1.1 等浏览器不会缓存通过 XMLHTTPRequest 获得的任何内容,并且无论服务器发送的标头如何,它总是会完全发送新数据(使用 Cache-Control 且没有 If-Modified-Since).
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.
显然那篇文章已经很老了——我什至不记得有 Firefox 1.1;那么对于当前流行的浏览器,我需要考虑哪些因素?当我特别想要缓存响应时有什么技巧吗?
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?
**为了澄清我的问题,缓存是指客户端缓存,其中服务器发布新鲜信息(以 Cache-Control: max-age 指令或 Expires: 标头的形式)并且浏览器存储在其缓存中的响应副本以及到期日期,以便可以从浏览器缓存中满足从后续页面发出的相同资源的未来请求,而根本不需要与服务器进行任何联系.所有主流浏览器都对大多数内容正确执行此操作,但我听说 Firefox 无法对 XMLHttpRequest 内容执行此操作.我要问的是,是否有人知道任何现代浏览器在使用 XMLHttpRequest 时不根据规范缓存响应的情况.*
**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.*
Mark Nottingham 有 an一组出色的功能测试,展示了浏览器 XMLHttpRequest 缓存行为.在您想要支持的浏览器中加载页面,并确定您可以依赖哪些技术以及不能依赖哪些技术来缓存您的响应.
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.
这篇关于哪些浏览器在缓存 XMLHTTPRequest 响应时存在问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!