manifest save for self

一、使用html5的缓存机制

1.先上规则代码:m.manifest

复制代码
CACHE MANIFEST
# 2015-04-24 14:20

#直接缓存的文件
CACHE:
/templates/specialty/css/style.css
/templates/specialty/js/jquery.js
/templates/specialty/js/index.js
/templates/specialty/js/custom.js
/templates/specialty/js/97zzw.js


NETWORK:
*
复制代码

CACHE: 需要缓存的文件

NETWORK: 需要从网络加载的文件

当然还有其他参数,但我只测试这些;注意:时常变化的就不要缓存了,如果已缓存可以通过修改manifest文件,让浏览器重新创建缓存。

2.在<html>中添加规则文件<html manifest="m.manifest">

复制代码
<!DOCTYPE html>
<html manifest="m.manifest">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
复制代码

3.manifest 文件需要配置正确的 MIME-type,即 "text/cache-manifest"。必须在 web 服务器上进行配置。

如果使用的是Apache,可在 .htaccess 中添加:

AddType text/cache-manifest manifest

以上3步完成,这时就可以测试了

chrome下:

缓存成功!继续测试————>

状态码304,使用缓存。

Firefox下:

总结:定义规则时注意要缓存那些不是时时更新的数据,不要漏写NETWORK规则;速度还是有非常明显的提升的。

posted @ 2015-04-24 17:19  junxizai  阅读(161)  评论(0编辑  收藏  举报