每个 URL 都可以链接到一个缓存清单。但我希望多个缓存清单链接到同一个 URL。原因如下:
我想要缓存的一些文件很少更新且很大。
因此,每次缓存更新时,这些大文件都会重新下载,即使它们可能没有更改。
所以我想分割缓存。一个缓存用于很少更新的大文件,另一个缓存用于经常更新的轻量文件。
你们知道如何分割 HTML5 缓存吗?
Every URL can be linked to a single cache manifest. But I want several cache manifests linked to a same URL. Here is the reason:
Some files I want to be cached are rarely updated and large.
So everytime the cache gets updated these large files get re-downloaded even though they may not have been changed.
So I want to split up the cache. One cache for theses rarely updated large files and another cache for the often updated light files.
Do you guys have any idea how to split up an HTML5 cache?
发布评论
评论(7)
最有效的方法是:
a) 对清单的 CACHE 部分中提到的所有资源使用远期到期日期 (max-age),并向 CACHE 部分中的每个文件添加时间戳后缀,例如:
b) 当上述任何文件发生更改时在服务器上,重新生成/更新清单以更改时间戳。下次只会下载具有修改时间戳的文件。任务完成了。
注意:在浏览器中重新加载页面两次,因为第一次刷新时浏览器仅下载清单并使用旧的缓存资源来绘制页面。这样做是为了加快页面显示速度(有一些技巧可以处理双重刷新问题,但它们超出了您的问题范围)
请参阅 这是我在 appcache 上见过的一篇很长但最好的文章。
The most efficient way is:
a) Use far-future expiration date (max-age) on all resources mentioned in manifest's CACHE section and add timestamp suffix to each file in the CACHE section, e.g.:
b) When any of the above files change on the server, regen/update manifest to change the timestamp. Only the file with the modified timestamp will get downloaded next time. Mission accomplished.
Note: Reload the page twice in the browser, as on the first refresh browser downloads just the manifest and uses old cached resources to paint the page. This is done to speed up displaying the page (there are tricks to handle this issue of double refresh, but they are outside the scope of your question)
See more info in this long but best article I ever seen on appcache.
使用 iframe
您的页面的缓存清单将包括轻文件,并且此页面加载的 iframe 的缓存清单将包括大文件
在 chrome 上,iframe 的应用程序缓存也将用于该页面。我还没有在其他浏览器上测试过这个方法。
请参阅 http://www.timer-tab.com 上的实时示例,如果您使用的是 chrome,请参阅它的分离缓存位于 chrome://appcache-internals/
Use an iframe
Your page's cache manifest would include the light files and the cache manifest of an iframe loaded by this page would include the large files
On chrome the iframe's application cache will also be used for the page. I didn't tested this method on other browsers yet.
see a live example at http://www.timer-tab.com and if you are using chrome see its split up cache at chrome://appcache-internals/
当清单文件发生更改并再次下载应用程序缓存的文件时,正常的 HTTP 缓存规则仍然适用。这意味着,如果您为这些大文件设置正确的 HTTP 缓存标头,您将收到 304,因此不会再次下载这些文件。所以没有必要分割应用程序缓存。
When the manifest file is changed and the files of the application cache are downloaded again, the normal HTTP caching rules still apply. This means that if you set the correct HTTP caching headers for these large files, you'll get a 304 so these files are not downloaded again. So it's not necessary to split the application cache.
也许是一个答案,但我更想在对自己的网络应用程序进行故障排除时阐明我的发现。
我发现我可以使用 2 个 iframe (manifest_framework) 和 (manifest_media) 来加载清单,但我仍然不太清楚它们是如何定位的,但我的成功有限。
Manifest_framework:
Manifest_media:
./index.php 是“着陆页”页面,它本身不会被缓存,但在离线时会回退到 webapp.php。
我不明白的是这些如何链接到 webapp.php 页面。
我发现我只能访问一个或另一个清单缓存。
上面的代码适用于 mobile safari,媒体和图像将被缓存,但不一定是框架清单中的 JS 或图像。
有人有更多从一个 URL/页面引用多个清单的示例吗?
Maybe an answer but I'd more like to shed some light on my findings as a I troubleshoot my own webapp.
I've discovered that I can use 2 iframes (manifest_framework) and (manifest_media) to load the manifests, but i'm still not exactly clear how they are targetted, but I had limited success.
manifest_framework:
manifest_media:
./index.php is the page the 'landing page' which itself isn't cached but falls back to webapp.php when offline.
What I don't understand is how these link to the webapp.php page.
I am finding I can only get access to one or the other manifests cache.
The above works in mobile safari, the media would be cached, and image but not necessarily the JS or images in the framework manifest.
Anyone have more examples where multiple manifests are referenced from the one URL/page?
W3C 工作组已放弃文件系统 api,因此不应再使用它。
我们可能会看到它从下一版本的 Chrome 中消失。
http://www.w3.org/TR/file-system-api/
The W3C working group has abandoned the file system api, so it SHOULD NOT BE USED anymore.
We'll likely see it fall off the next version of Chrome.
http://www.w3.org/TR/file-system-api/
如果 Iframe 技巧不起作用,请使用 HTML5 FileSystem API
请参阅 http://updates.html5rocks.com/2012/04/Taking-an-Entire-Page-Offline-using-the-HTML5-FileSystem-API
If the Iframe trick does not work, use the HTML5 FileSystem API
See http://updates.html5rocks.com/2012/04/Taking-an-Entire-Page-Offline-using-the-HTML5-FileSystem-API