一旦 HTML 文档有了清单 (cache.manifest),如何删除它?

发布于 2024-10-09 12:37:06 字数 636 浏览 13 评论 0原文

似乎一旦你有了一个清单条目,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

嘿哥们儿 2024-10-16 12:37:06

我一直在研究同样的问题,它似乎不是一个API:

  1. 动态触发页面被缓存
  2. ,动态导致页面停止被缓存。

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

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 或 410 响应或同等响应而导致获取清单失败,请运行以下子步骤:
将缓存组标记为已过时。除了处理已经与缓存组中的应用程序缓存关联的文档对象之外,该缓存组不再出于任何目的而存在。
如果缓存组中存在完整性标志不完整的应用程序缓存,则丢弃该应用程序缓存。

然后它说:

如果这是一次缓存尝试,则完全丢弃缓存组。

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

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

  1. dynamically trigger that a page is cached
  2. dynamically cause a page to stop being cached.

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.

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:

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.

It then says:

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

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?).

眼藏柔 2024-10-16 12:37:06

一种可能的解决方案:

  • 修改清单(因此它会重新加载)
  • 修改主文件(index.html)以引用不存在的清单,因此它会出现 404

很难优雅,但它似乎可以工作。那么主要的问题是,您将陷入这个生成 404 错误的清单条目,直到所有访问过您网站的人都返回并清除了缓存。

必须有更好的方法...

One possible solution:

  • modify the manifest (so it reloads)
  • modify the master file (index.html) to reference a non-existant manifest, so it gets a 404

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...

你怎么这么可爱啊 2024-10-16 12:37:06

尝试简单地删除清单文件。来自 mozzila 文档:

应用程序缓存也可能会过时。如果从服务器中删除清单,浏览器将删除使用该清单的所有应用程序缓存,然后向应用程序缓存对象发送“废弃”事件。然后应用程序缓存的状态将设置为 OBSOLETE。

这对我在 chrome 上也有用。

Try to simply delete the manifest file. From the mozzila docs :

Application caches can also become obsolete. If the manifest is removed from the server, the browser removes all application caches that use that manifest, then sends an "obsoleted" event to the application cache object. Then the application cache's status is set to OBSOLETE.

This also worked for me on chrome.

一身骄傲 2024-10-16 12:37:06

如果您使用的是 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.

对不⑦ 2024-10-16 12:37:06

我们所做的就是删除清单中的文件列表,这样就不会缓存任何文件。

它对我们有用。

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.

冬天旳寂寞 2024-10-16 12:37:06

这可能很旧,但希望对某人仍然有帮助。

查看 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.

a√萤火虫的光℡ 2024-10-16 12:37:06

出于开发目的(不断变化),我们所做的是:

  1. 在你的SERVER-SIDE语言下设置一个-缓存清单文件-,例如我们使用PHP,所以我们的开发缓存是称为“cache.manifest.php”,它在 html 标记中以相同的方式指向,如下所示:

    
    
  2. 将一些与时间相关的字符串(或其他适合您的内容)作为注释 (#---) 放在清单中的某个位置,以便文件每隔一段时间就会有所不同(浏览器)似乎比较清单的内容,而不是日期),例如此字符串每分钟都会更改清单,这样如果访问与上次访问的时间不同,所有文件都将被重新缓存。

    
    

我们刚刚使用 Chrome 测试了这个过程,希望它适用于其他人,但如果不行,我们将非常感谢您的评论和建议。

For development purposes (constant changes), what we have done is:

  1. 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:

    <html manifest="cache.manifest.php">
    
  2. 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.

    <?php if($dev) echo date("Y-m-d H:m"); ?>
    

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文