克服 Firefox 上页面的不可缓存性
我正在尝试构建 Firefox 的扩展,以从网络服务器获取页面并将其放入浏览器的缓存中,这样当用户请求该链接时,将直接从缓存中检索它,而不是要求原始网络服务器。
但我在处理某些页面时遇到了麻烦,这些页面放置标头以避免可缓存性,例如“Cache-control:must-revalidate”、“Cache-control:no-store”、“Cache-control:no-cache”和“Pragma” :无缓存”。
当页面到达时,我试图用 nsIHttpChannel 的 setResponseHeader 覆盖这些标头。但相应缓存条目中的标头并未更改。然后我尝试 nsICacheEntryDescriptor 的 setMetaDataElement 来更改元数据键“response-head”。尽管数据已更改,但仍从原始 Web 服务器检索页面。
有谁知道如何克服这个问题并使页面从 Firefox 的缓存加载?这可能吗?
提前致谢。
I'm trying to build an extension to Firefox to get a page from a web server and put it in the browser's cache, so that when the user asks for that link, it'll be retrieved directly from the cache, instead of asking to the original web server.
But I'm having trouble with some pages which put headers to avoid cacheability, such as "Cache-control: must-revalidate", "Cache-control: no-store", "Cache-control: no-cache" and "Pragma: no-cache".
I'm trying to overwrite those headers with nsIHttpChannel's setResponseHeader when the page arrives. But the headers are not changed in the corresponding cache entry. Then I try nsICacheEntryDescriptor's setMetaDataElement to change the metadata key "response-head". Though the data is changed, the page still is being retrieved from the original web server.
Does anyone know how to overcome this problem and make the pages be loaded from Firefox's cache? Is this possible?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 XMLHttpRequest 来检索页面,问题是我更改了我所做的“onreadystatechange”函数中的响应标头。
或者,我将观察者用于“http-on-examine-response”,并更改“observe”方法中的响应标头。更改现在由缓存保存。
我通过查看 BetterCache Firefox 扩展获得了见解代码。
I was using XMLHttpRequest to retrieve the page, and the problem was that I changed the response headers in the "onreadystatechange" function I made.
Alternatevely, I used the observer for "http-on-examine-response", and altered the response headers in the "observe" method. The change is now being kept by the cache.
I've got the insight by looking at the BetterCache Firefox extension's code.