Chrome 中的明显行为不稳定

发布于 2024-10-14 15:11:37 字数 690 浏览 0 评论 0原文

您是否曾经让 HTML 缓存清单在 Chrome 中按预期工作?我已经完成了一个小项目,但显然效果不佳。它有效!

我创建了一个像这样的 HTML 页面:

<html manifest="cache.manifest">
<body>
 test - <img src="img1.jpg" width="100" height="100">
</body>
</html>

一个像这样的清单:

CACHE MANIFEST
#V1.0.22
img1.jpg

NETWORK:
*

同一文件夹中有 2 个图像:img1.jpg 和 img2.jpg。

当我交换图像时,img2=>img1 并更新清单的版本号,Chrome 会下载新版本并发送更新就绪事件。当我重新加载页面时,我在屏幕上看到了第二张图像,这是预期的。不过,如果我用原始图像覆盖 img1,更新清单中的版本号并重新加载,Chrome 会下载新的清单和新文件,但即使我一次又一次刷新页面,它也不会显示正确的图像! !如果我当时清除缓存,我会得到正确的缓存,这也是我所期望的。我已经做了10次了,还是不行。这让我发疯!看来缓存替换不能正常工作!

如果您对此有任何线索,请告诉我。如果您愿意,我什至可以通过电子邮件向您发送我的文件。

干杯。

Have you ever got a HTML cache manifest working as expected in Chrome ? I've put a little project together and apparently it doesn't work well. It works-ish !

I've created an HTML page like this:

<html manifest="cache.manifest">
<body>
 test - <img src="img1.jpg" width="100" height="100">
</body>
</html>

A manifest like this:

CACHE MANIFEST
#V1.0.22
img1.jpg

NETWORK:
*

And 2 images in the same folder: img1.jpg and img2.jpg.

When I swap my images round, img2=>img1 and update the version number of my manifest, Chrome downloads the new version and sends the update ready event. When I reload the page, I get my second image on the screen which is what's expected. Though, if I overwrite the img1 with the original image, update the version number in the manifest and reload, Chrome downloads the new manifest and the new file but even if I refresh the page again and again it doesn't display the correct image !! If I clear the cache at that point, I get the correct one which is what I would expect as well. I've done 10 times and it doesn't work. this is driving me crazy! It seems like the cache replacement doesn't work properly!

If you have a clue about this please tell me. I can even send you my files by email if you want.

Cheers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

红ご颜醉 2024-10-21 15:11:37

这很可能是cache.manifest 缓存和普通浏览器缓存之间的不良交互。使用cache.manifest时,您的浏览器仍然遵循http标头中的正常浏览器缓存规则。因此,当您提供图像时,其标头表示可以将其缓存几个小时或几天。它还通过cache.manifest 进行缓存。您在服务器上更新您的映像,并更改您的cache.manifest 版本号。浏览器看到版本更改,清除cache.manifest,并正常再次请求图像。但像平常一样,当请求图像时,它首先检查浏览器缓存,然后从那里提取旧图像,而不是获取服务器上的图像。然后它将这个旧图像粘回到cache.manifest中。因此,即使浏览器缓存中图像的缓存时间到期,图像仍然不会更新,因为它现在再次缓存在cache.manifest中。

简而言之,cache.manifest 和普通的浏览器缓存构成了一个非常糟糕的组合,因此您需要对放入 cache.manifest 文件的任何内容禁用浏览器缓存。您可以通过更改缓存标头在服务器上执行此操作。

This is very likely to be a bad interaction between the cache.manifest caching, and normal browser caching. When using cache.manifest, your browser still also follows normal browser caching rules in your http headers. So what happens is that you serve an image up and its header says it's ok to cache it for a few hours or days. It also gets cached by cache.manifest. You update your image on the server, and change your cache.manifest version number. The browser sees the version change, clears the cache.manifest, and requests the image again as normal. But as normal, when requesting the image, it checks the browser cache first, and it pulls the old image out of there instead of grabbing the one on the server. Then it sticks this old image back into cache.manifest. So even after the cache time for the image expires in the browser cache, the image still won't updated because it's now cached again in the cache.manifest.

In short, cache.manifest and normal browser caching make for a really terrible combination, so you need to disable browser caching for anything that you're putting into a cache.manifest file. You can do this on your server by changing the cache headers.

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