HTML5 离线:即使在线,浏览器也会加载缓存的索引页面
当请求页面时,它会根据清单文件进行缓存。但是,当页面更新且设备在线时,即使计算机离线(在线),文件也不会更新。
我们如何解决这个问题?有没有办法告诉客户端在线时从服务器加载页面而不是缓存?
When a page is requested, it is cached as per the manifest file. However, when the page is updated, and the device is online, the file is not updated even though the computer is offline (it's online).
How can we work around this? Is there any way to tell the client to load the page from the server and not the cache when it's online?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已缓存的离线应用程序在尝试上线之前始终会从缓存中加载。
话虽如此,您可以创建一个动态缓存清单,如果任何文件发生更改,即使没有添加/删除文件,该清单也会自行更新。本质上,您创建每个文件的哈希值,如果哈希值发生变化,清单就会更新。我在此处更详细地解释了如何执行此操作(概念最初发布此处)。
An offline app that has been cached will always load from the cache before attempting to go online.
Having said that, you can create a dynamic cache manifest that will update itself if any file has changed, even if no files have been added/removed. Essentially you create a hash of each file, and if the hash changes the manifest is updated. I explain how to do this in more detail here (concept originally published here).
请看这里:http://www.w3.org/TR/html5/offline。 html#appcacheevents
显然,当页面声明清单时,浏览器应该查看清单文件以查看是否有任何更改,然后刷新它提到的所有资源(如果有)。如果清单文件未更改,则不会刷新任何其他内容。
我想您会更改清单文件中的注释,以便当实际的资源名称列表没有更改时(也许是版本号或日期注释),它会被视为已更改。
Look here: http://www.w3.org/TR/html5/offline.html#appcacheevents
Apparently, when a page declares a manifest, the browser should look at the manifest file to see if anything has changed, and then refresh all the resources it mentions if it has. If the manifest file has not changed, then nothing else is refreshed.
I guess you would change a comment in the manifest file, so that it will be seen to have changed, when the actual list of resource names has not changed -- perhaps, a version number or date comment.