问题描述
我对HTML5缓存有点慢,但我只有一些简单的问题。
I am a little slow to the HTML5 caching, I have just some simple questions though.
1)数据有多长缓存缓存清单?
1) How long is data in a caching manifest cached?
2)如果我更新数据,如何确保客户端检查更新的版本可用,或者这已经完成了吗?
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?
3)此外,这对于非0移动环境是否完全无用,或者是否可以加速加载桌面上的时间?
3) Also, is this completely useless for a non-0mobile environment or can it speed up load times on a desktop?
<html lang="en" manifest="offline.manifest">
offline.manifest
offline.manifest
CACHE MANIFEST
index.html
style.css
image.jpg
image-med.jpg
image-small.jpg
notre-dame.jpg
推荐答案
1)只要用户关心缓存它。完全摆脱缓存的唯一方法是进入浏览器设置并明确删除它。
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)如果更新清单文件,客户端将下载所有文件的新版本。此下载仍受旧HTTP缓存规则的约束,因此请适当设置标头,同时确保在清单文件本身上发送无缓存标头。来自HTML5 Boilerplate的可能是一个很好的起点。
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)记住桌面也会丢失连接。此外,在应用程序缓存中放置文件意味着它们始终在本地提供,因此,如果您对放入其中的内容感到理解,则应用程序缓存可以减少带宽和延迟。我明白的意思是:如果大多数访问者只看到您网站的几页并且每周更新整个网站的清单,那么如果您强迫他们缓存负载,他们最终可能会使用更多带宽他们永远不会看到的页面的静态文件。
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.
要真正减少未来HTML5网站的带宽和延迟:对所有资产使用应用程序缓存静态框架;使用之类的内容来呈现JSON中的所有内容;通过而不是HTTP发送JSON,为您节省大约800字节和双向网络每次请求握手;使用缓存数据,以节省您再次获取数据,并使用历史API 。
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.
这篇关于基本的HTML5缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!