html5离线缓存使用

html5 离线缓存使用以及注意事项

1、index.html中加入离线缓存的声明文件 如:
<!DOCTYPE html>
<html manifest="test.appcache">

test.appcache 与 index.html在相同路径下。

2、服务器端加入MIME TYPE声明:
tomcat如下 web.xml中加入
<mime-mapping>
<extension>manifest</extension>
<mime-type>text/cache-manifest</mime-type>
</mime-mapping>

3、编写test.appcache文件
CACHE MANIFEST
# 2016-04-26
#v1.0.9

CACHE:
css/my.css
js/my.js

NETWORK:
*
FALLBACK:
/html5/ /404.html
第一行必须为CACHE MANIFEST
CACHE:配置要缓存的文件不可以使用通配符
NETWORK:配置不缓存的文件,可以使用通配符表示其他文件都不缓存
FALLBACK:规定当页面无法访问时的回退页面

4、可以通过更改test.appcache中的注释如版本号是浏览器更新缓存文件,第二次打开页面时使用新的文件

5、当index.html也被缓存的情况下可以通过更改test.appcache文件名来更新缓存文件。