一旦 HTML 文档有了清单 (cache.manifest),如何删除它?
似乎一旦你有了一个清单条目,a la:
<html manifest="cache.manifest">
那么该页面(缓存中的主条目)将始终被缓存(至少通过 Safari),直到用户执行某些操作来删除缓存,即使您稍后删除了该页面html 标签中的清单属性并更新清单(通过更改其中的某些内容),强制主条目与其他所有内容一起重新加载。
换句话说,如果你有:
- index.html(定义了manifest)
- file1.js(在manifest中引用)
- file2.js(在manifest中引用)
- cache.manifest(列出了两个js 文件)
——从 index.html 中删除清单条目并修改清单(因此它会被浏览器过期并重新加载所有内容)不会阻止此页面的行为,就好像它仍然完全缓存一样。如果您在index.html上查看源代码,您将不会再看到列出的清单,但浏览器仍将仅请求cache.manifest文件,除非该文件的内容发生更改,否则任何文件的其他更改都不会显示给用户。
这看起来是一个非常明显的错误,它存在于 iOS 和 Mac 版本的 Safari 上。有没有人找到一种无需用户干预即可重置页面并摆脱缓存的方法?
It seems that once you have a manifest entry, a la:
<html manifest="cache.manifest">
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.
In other words, if you have:
- index.html (with manifest defined)
- file1.js (referenced in manifest)
- file2.js (referenced in manifest)
- cache.manifest (lists the two js
files)
-- 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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我一直在研究同样的问题,它似乎不是一个API:
以下是我找到的最佳资源:
http://www.html5rocks.com/tutorials/appcache/beginner/
http://www.thecssninja.com/javascript/how- to-create-offline-webapps-on-the-iphone
特别是,第一个链接中的引用:
否则,没有任何地方提到卸载缓存。
似乎表明您不能强制发生错误以使其取消缓存。但是,如下所述,规范建议如果在下载清单文件时发生错误,则整个缓存将被删除。
在 google chrome 中,用户可以访问以下 URL:
chrome://appcache-internals/
并手动禁用缓存。当然,下次访问该页面时,如果该页面设置了清单属性,则会重新缓存该页面。
如果您查看规范:5.6 离线 Web 应用程序
它似乎建议缓存被删除的情况。具体来说,第 5.6.4.5 节:
然后它说:
基本上,如果对缓存清单文件的请求导致 404,则应丢弃整个缓存。那么,您是否尝试过在请求缓存清单文件时让服务器返回 404 或 410 ?那应该有效。诀窍是只返回您想要从中删除清单的页面的 404 / 410(也许使用 url 参数?)。
Ive been researching the same question, and it doesnt appear to be an api to:
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:
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.
If you look at the specification:5.6 Offline Web applications
It seems to suggest a situation where the cache is removed. Specifically, section 5.6.4.5:
It then says:
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?).
一种可能的解决方案:
很难优雅,但它似乎可以工作。那么主要的问题是,您将陷入这个生成 404 错误的清单条目,直到所有访问过您网站的人都返回并清除了缓存。
必须有更好的方法...
One possible solution:
Hardly elegant, but it seems to work. The main problem then is that you're stuck with this 404-generating false manifest entry until everyone who has ever been to your site has returned and had their cache cleared.
There has got to be a better way...
尝试简单地删除清单文件。来自 mozzila 文档:
这对我在 chrome 上也有用。
Try to simply delete the manifest file. From the mozzila docs :
This also worked for me on chrome.
如果您使用的是 IIS 7,一种解决方案是删除为启用缓存而添加的 .manifest 或 .appcache 文件类型的 Mime 类型。当您想再次启用缓存时,您可以随时将其添加回来。这就是我为修复我所做的。
One solution, if you are using IIS 7 is to remove the Mime Type for the .manifest or .appcache file type that you added to enable caching. You can always add this back when you want to enable caching again. This is what I did to fix mine.
我们所做的就是删除清单中的文件列表,这样就不会缓存任何文件。
它对我们有用。
What we do is delete the list of files in the manifest, so it stands out NO file will be cached.
It works for us.
这可能很旧,但希望对某人仍然有帮助。
查看 IIS 属性中的 HTTP 标头。查看启用或禁用内容过期。可能是 IIS 仍在进行缓存。
This might be old but hopefully still helpful to someone.
Take a look at your HTTP headers in IIS properties. Take a look at enabling or disabling content expiration. It might be that IIS is still doing the cache.
出于开发目的(不断变化),我们所做的是:
在你的SERVER-SIDE语言下设置一个-缓存清单文件-,例如我们使用PHP,所以我们的开发缓存是称为“cache.manifest.php”,它在 html 标记中以相同的方式指向,如下所示:
将一些与时间相关的字符串(或其他适合您的内容)作为注释 (#---) 放在清单中的某个位置,以便文件每隔一段时间就会有所不同(浏览器)似乎比较清单的内容,而不是日期),例如此字符串每分钟都会更改清单,这样如果访问与上次访问的时间不同,所有文件都将被重新缓存。
我们刚刚使用 Chrome 测试了这个过程,希望它适用于其他人,但如果不行,我们将非常感谢您的评论和建议。
For development purposes (constant changes), what we have done is:
Set a -cache manifest file- under your SERVER-SIDE language, for example, we use PHP, so our development cache is called "cache.manifest.php" and it's pointed this same way in the html tag like this:
Put some -time dependent- string (or something else that suites you) somewhere in your manifest as a comment (#---), so that the file is different every once in a while (browsers seem to compare manifest's content, not date), for example this string changes the manifest every minute, this way all files would be re-cached if the visit is in a different minute as the last time.
We've just tested this procedure using Chrome, hope it works in others, but if not your comments and advices would be very well appreciated.