开发者

Manifest behaviour in chrome is not stable

开发者 https://www.devze.com 2023-02-07 06:50 出处:网络
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 wo开发者_运维百科rk well. It works-ish !

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 wo开发者_运维百科rk 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号