HTML5缓存 - 是否有可能为单个网址提供多个不同的缓存? [英] HTML5 Cache -- Is it possible to have several distinct caches for a single URL?

查看:172
本文介绍了HTML5缓存 - 是否有可能为单个网址提供多个不同的缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个URL都可以链接到单个缓存清单。但我想要几个缓存清单链接到同一个URL。原因如下:

我想要缓存的某些文件很少更新且很大。
因此,每次缓存得到更新时,即使这些文件可能没有被更改,也会重新下载这些大文件。
所以我想分割缓存。本文的一个缓存很少更新大文件,而另一个缓存则用于经常更新的轻量级文件。



你们有没有想法如何拆分HTML5缓存?

解决方案

最有效的方法是:a)使用远期到期date清单的CACHE部分中提到的所有资源上的日期(max-age),并为CACHE部分中的每个文件添加时间戳后缀,例如:

 
CACHE:
menu_1355817388000.js
toolbar_1355817389100.js



b)当上述任何文件在服务器上发生更改时,重新生成/更新清单以更改时间戳。只有下次修改时间戳的文件才会被下载。任务完成。
$ b

注意:在浏览器中重新加载页面两次,因为第一次刷新浏览器只下载清单并使用旧的缓存资源来绘制页面。这是为了加快显示页面(有处理这个问题的双刷新技巧,但它们超出了你的问题的范围)。

查看更多信息这篇我在appcache上见过的长篇但最好的文章


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?

解决方案

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.:

CACHE:
menu_1355817388000.js
toolbar_1355817389100.js

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.

这篇关于HTML5缓存 - 是否有可能为单个网址提供多个不同的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆