日期:2014-05-17  浏览次数:20601 次

html5的离线存储applicationCache应用
需要注意几点:
1、可以通过iframe嵌入多个manifest文件。主页不需要配置manifest,这样index.html就不会被缓存。
<iframe id="iframe1" src="cache1.html" frameborder="no" scrolling="no">
        </iframe>
<iframe id="iframe2" src="cache2.html" frameborder="no" scrolling="no">
        </iframe>
<iframe id="iframe2" src="cache3.html" frameborder="no" scrolling="no">
        </iframe>
2、多个manifest文件还是会有空间的限制,在ipad的safari上不能超过50M。若cache1.manfest是26M,cache1.manfest是27M,则2个加起来超过50m,这时,首先cached完cache1,当缓存cache2的时候,会报一个超过缓存容量限制的错误。cache3自然也不会保存了。只保存了第一个cache1.
3、必须reload页面才会使缓存更新生效。
4、手动检查cache的更新。applicationCache.update();
5、手动执行更新。
applicationCache.addEventListener("updateready", function() {
         if (confirm("本地缓存已被更新,是否刷新?")) {
        // (3) 手工更新本地缓存
            applicationCache.swapCache();
            // 重载画面
            location.reload();
        }
    }, true);
applicationCache.swapCache();必须放在updateready中执行。
6、manifest文件中的配置文件可以不被html使用。但是若缓存xml等文件,好像缓存不了。
7、NETWORK:若除了CACHE:定义的文件之外的文件都不要缓存,则NETWORD:下必须写个*.否则可能造成CACHE外的文件全部加载不了。
8、CACHE:下不能使用文件夹形式定义。如images/。这样方式不会被识别。
而且文件路径和文件名不能包含空格,否则只会取得空格之前的文本,导致文件缓存失败。
9、若manifest文件删除了之前缓存的文件,则浏览器也会删除缓存的文件并更新。