manifest save for self

1、使用html5的缓存机制css

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

复制代码
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: 须要缓存的文件html5

NETWORK: 须要从网络加载的文件jquery

固然还有其余参数,但我只测试这些;注意:时常变化的就不要缓存了,若是已缓存能够经过修改manifest文件,让浏览器从新建立缓存。web

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

复制代码
<!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规则;速度仍是有很是明显的提高的。

相关文章
相关标签/搜索