4

在设置prefer-online设置时,我希望浏览器在每次刷新浏览器时都请求页面,但事实并非如此。

这是我的清单:

CACHE MANIFEST

SETTINGS:
prefer-online

NETWORK:
*

然而,当我刷新浏览器时,它只向服务器请求清单。它只在我更新清单时请求页面......

并且页面上没有设置标题(过期或最大年龄)。

(在 chrome 和 firefox 上测试)

注意:更新清单时,浏览器会重新下载资产,但仍会显示旧版本……只有在下次加载时,浏览器才会使用新资产。为什么 ?

4

1 回答 1

0

我看不到 AppCache 清单的用途,因为您想绕过缓存并只使用网络。请记住,无论 AppCache 清单如何,常规缓存可能仍然适用,因此请检查Expires,Last-Modified和类似的标头。

至于你的问题:

注意:更新清单时,浏览器会重新下载资产,但仍会显示旧版本……只有在下次加载时,浏览器才会使用新资产。为什么 ?

这是因为用户代理将立即使用您的资产的最新缓存版本,然后开始检查清单中列出的链接资源是否有更新。当用户代理检测到清单已更改,因此它必须检查更新时,它将触发一个checking事件。

When the update checking process has finished (and it might take a long time, if you have lots of resources) it will fire an updateready event. Only the resources fetched after this event will be the fresh new ones (that's why it's usually adviceable to use window.applicationCache.swapCache() to tell the browser to swap the old cache for the new for the next page load, or simply reload the page and be done with it).

You will find more detailed explanations about these topics here: http://www.html5rocks.com/en/tutorials/appcache/beginner/

于 2013-09-24T13:40:59.383 回答