一旦HTML文档有一个清单(cache.manifest),你怎么能删除它? [英] Once an HTML document has a manifest (cache.manifest), how can you remove it?

查看:160
本文介绍了一旦HTML文档有一个清单(cache.manifest),你怎么能删除它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎一旦你有一个清单条目,la:

It seems that once you have a manifest entry, a la:

<html manifest="cache.manifest">

然后该页面(缓存中的主条目)将始终被缓存(至少通过Safari)直到用户执行删除缓存的操作,即使您稍后从html标记中删除清单属性并更新清单(通过更改其中的内容),也会强制主条目与其他所有内容一起重新加载。

Then that page (the master entry in the cache) will always be cached (at least by Safari) until the user does something to remove the cache, even if you later remove the manifest attribute from the html tag and update the manifest (by changing something within it), forcing the master entry to be reloaded along with everything else.

换句话说,如果你有:


  • index.html(已定义清单)

  • file1.js(在清单中引用)

  • file2.js(在清单中引用)

  • 缓存。 manifest(列出两个js
    文件)

  • index.html (with manifest defined)
  • file1.js (referenced in manifest)
  • file2.js (referenced in manifest)
  • cache.manifest (lists the two js files)

- 从index.html中删除清单条目并修改清单(所以它被浏览器过期并重新加载所有内容)不会阻止此页面表现得好像它仍然完全缓存一样。如果您在index.html上查看源代码,您将不再看到列出的清单,但浏览器仍将仅请求cache.manifest文件,除非该文件的内容已更改,否则不会对任何文件进行任何其他更改。用户。

-- removing the manifest entry from index.html and modifying the manifest (so it gets expired by the browser and all content reloaded) will not stop this page from behaving as if it's still fully cached. If you view source on index.html you won't see the manifest listed anymore, but the browser will still request only the cache.manifest file, and unless that file's content is changed, no other changes to any files will be shown to the user.

这似乎是一个非常明显的错误,它出现在iOS和Mac版本的Safari上。有没有人找到一种方法来重置页面并摆脱缓存而无需用户干预?

It seems like a pretty glaring bug, and it's present on iOS as well as Mac versions of Safari. Has anyone found a way of resetting the page and getting rid of the cache without requiring user intervention?

推荐答案

我一直在研究问题,它似乎不是一个api:

Ive been researching the same question, and it doesnt appear to be an api to:


  1. 动态触发页面缓存

  2. 动态地导致页面停止缓存。

以下是我找到的最佳资源:

Here are the best resources I have found:

http://www.html5rocks.com/tutorials/appcache/beginner/

http://www.thecssninja.com/javascript/how-to-create-offline-webapps-on-the-iphone

特别是这个引自第一个链接:

In particular, this quote from the first link:


如果清单文件或其中指定的资源无法下载,则整个更新将失败。如果发生此类故障,浏览器将继续使用旧的应用程序缓存。

If the manifest file or a resource specified in it fails to download, the entire update fails. The browser will continue to use the old application cache in the event of such a failure.

否则,任何地方都没有提及卸载缓存。

Otherwise, there is no mention anywhere about unloading the cache.

似乎暗示您无法强制执行错误以使其无法缓存。但是,如下所述,规范建议如果在下载清单文件时发生错误,整个缓存将被删除。

Seems to suggest that you cant force an error to get it to uncache. However, as noted below, the spec suggests that if an error occurs while downloading the manifest file, the entire cache will be removed.

在谷歌浏览器中,用户可以去到以下网址:

In google chrome, the user can go to the following URL:

chrome:// appcache-internals /

并手动禁用缓存。当然,下次他们访问页面时,如果页面设置了清单属性,它将被重新跟踪。

And manually disable the cache. Of course, the next time they visit the page, it will be recached if the page has the manifest property set.

如果查看规范:5.6离线Web应用程序

它似乎建议删除缓存的情况。具体来说,第5.6.4.5节:

It seems to suggest a situation where the cache is removed. Specifically, section 5.6.4.5:


如果由于404或410响应或等效响应而导致清单失败,则运行以下子步骤:
将缓存组标记为已过时。除了处理已与缓存组中的应用程序缓存关联的Document对象之外,此缓存组不再用于任何其他目的。
如果缓存组有一个完整性标记不完整的应用程序缓存,则丢弃该应用程序缓存。

If fetching the manifest fails due to a 404 or 410 response or equivalent, then run these substeps: Mark cache group as obsolete. This cache group no longer exists for any purpose other than the processing of Document objects already associated with an application cache in the cache group. If cache group has an application cache whose completeness flag is incomplete, then discard that application cache.

然后说:


如果这是缓存尝试,请完全丢弃缓存组。

If this was a cache attempt, discard cache group altogether.

基本上,如果对缓存清单文件的请求导致404,则应丢弃整个缓存。那么,您是否尝试过在请求缓存清单文件时服务器返回404或410?这应该工作。诀窍是只返回要从中删除清单的页面的404/410(可能使用url参数?)。

Basically, if the request for the cache manifest file results in a 404, then the entire cache should be discarded. So, have you tried to have the server return a 404 or 410 when the cache manifest file is requested? That should work. The trick is to only return the 404 / 410 for the pages you want to remove the manifest from (perhaps using url parameters?).

这篇关于一旦HTML文档有一个清单(cache.manifest),你怎么能删除它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆