問題描述
目前流行的瀏覽器是否存在緩存* XMLHttpRequest 響應的特殊問題,我需要注意這些問題?
Do any of the currently popular browsers have particular problems caching* XMLHttpRequest responses that I need to be aware of?
我希望能夠在每個頁面上包含 XMLHttpRequest 查詢,作為動態(tài)加載與頁面類型相關(guān)的內(nèi)容(即 JSON)或行為(如 eval()ed Javascript)的方法,但想確保如果服務器發(fā)送了正確的標頭,它從服務器接收的資源可以被緩存.
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 獲得的任何內(nèi)容,并且無論服務器發(fā)送的標頭如何,它總是會完全發(fā)送新數(shù)據(jù)(使用 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.
顯然那篇文章已經(jīng)很老了——我什至不記得有 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?
**為了澄清我的問題,緩存是指客戶端緩存,其中服務器發(fā)布新鮮信息(以 Cache-Control: max-age 指令或 Expires: 標頭的形式)并且瀏覽器存儲在其緩存中的響應副本以及到期日期,以便可以從瀏覽器緩存中滿足從后續(xù)頁面發(fā)出的相同資源的未來請求,而根本不需要與服務器進行任何聯(lián)系.所有主流瀏覽器都對大多數(shù)內(nèi)容正確執(zhí)行此操作,但我聽說 Firefox 無法對 XMLHttpRequest 內(nèi)容執(zhí)行此操作.我要問的是,是否有人知道任何現(xiàn)代瀏覽器在使用 XMLHttpRequest 時不根據(jù)規(guī)范緩存響應的情況.*
**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 緩存行為.在您想要支持的瀏覽器中加載頁面,并確定您可以依賴哪些技術(shù)以及不能依賴哪些技術(shù)來緩存您的響應.
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.
這篇關(guān)于哪些瀏覽器在緩存 XMLHTTPRequest 響應時存在問題?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!