基本 HTML5 缓存
我对 HTML5 缓存有点慢,但我只有一些简单的问题。
1) 缓存清单中的数据会缓存多长时间?
2) 如果我更新数据,如何确保客户端在可用时检查是否有新版本,或者是否已经完成?
3) 另外,这对于非 0 移动环境完全没用吗?还是可以加快桌面上的加载时间?
<html lang="en" manifest="offline.manifest">
离线清单
CACHE MANIFEST
index.html
style.css
image.jpg
image-med.jpg
image-small.jpg
notre-dame.jpg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1)只要用户愿意缓存即可。完全摆脱缓存的唯一方法是进入浏览器设置并明确删除它。
2) 如果更新manifest文件,客户端将下载所有文件的新版本。此下载仍然受“旧”HTTP 缓存规则控制,因此请适当设置标头,还要确保在清单文件本身上发送“无缓存”标头。 HTML5 Boilerplate 的规则可能是一个不错的起点。
3) 请记住,桌面也可能会失去连接。此外,将文件放在应用程序缓存中意味着它们始终在本地提供,因此,只要您了解放入其中的内容,应用程序缓存就可以减少带宽和延迟。我所说的明智的意思是:如果大多数访问者只看到您网站的几个页面,而您每周更新整个网站的清单,那么如果您强迫他们缓存大量内容,他们最终可能会使用更多的带宽。他们从不查看的页面的静态文件。
要真正减少未来 HTML5 网站的带宽和延迟:对所有资源和静态框架使用应用程序缓存;使用 mustache 之类的东西来渲染 JSON 中的所有内容;通过 Web Sockets 而不是 HTTP 发送 JSON,节省约 800 字节和双向网络根据请求握手;使用本地存储缓存数据,以便您无需再次获取数据,并使用历史 API。
1) As long as the user cares to cache it. The only way to completely get rid of the cache is to go into the browser settings and explicitly remove it.
2) If you update the manifest file, the client will download new versions of all the files. This download is still governed by 'old' HTTP caching rules, so set headers appropriately, also make sure you send a 'no-cache' header on the manifest file itself. The rules from HTML5 Boilerplate are probably a good place to start.
3) Remember desktops can lose connectivity too. Also, having files in application cache means they are always served locally so, providing you're sensible about what you put in it, the application cache can reduce bandwidth and latency. What I mean by sensible is: if most visitors only see a couple of pages of your site and you update the manifest of your entire site every week, then they could end up using more bandwidth if you're forcing them to cache a load of static files for pages they never look at.
To really cut down on bandwidth and latency in your HTML5 website of the future: use the application cache for all your assets and a static framework; use something like mustache to render all your content from JSON; send that JSON over Web Sockets instead of HTTP, saving you ~800 bytes and a two way network handshake per request; cache data with Local Storage to save you fetching it again, and manage navigation with the History API.
1) 缓存清单中的数据会缓存多长时间?
一旦应用程序被缓存,它将保持缓存状态,直到发生以下情况之一:
用户清除浏览器缓存
清单文件被修改
应用程序缓存以编程方式更新
2) 如果我更新数据,如何确保客户端在可用时检查更新版本,或者这是否已经完成?
您可以指定不缓存的女巫文件(网络:)
如果你想更新你的缓存文件,你应该修改清单文件中的一些内容,最好的方法是在文件中添加注释,并在你希望浏览器更新缓存时更改它
3)另外,这对于非移动环境还是可以加快桌面上的加载时间?
是的,它很有用,因为互联网可以在所有设备上切断
1) How long is data in a caching manifest cached?
Once an application is cached, it remains cached until one of the following happens:
The user clears the browser's cache
The manifest file is modified
The application cache is programatically updated
2) If I update the data, how can I make sure the client checks for a newer version when it is available, or is this already done?
you can specify witch files not to cache (NETWORK:)
If you want to update your cached files, you should modify something in the manifest file, the best way is to put comment in the file and change it when you want the browser to update the cache
3) Also, is this completely useless for a non-mobile environment or can it speed up load times on a desktop?
Yes it is useful, cause the internet can cut on all devices