首页 > 网站 > WEB开发 > 正文

记一次页面优化及使用缓存机制

2024-04-27 14:27:20
字体:
来源:转载
供稿:网友
记一次页面优化及使用缓存机制

一、使用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.jsNETWORK:*

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

PRVFdX9/f3FxYW/vTTT8ZNKnR/f390dPSeX6ipqenq6oqOju7q6tpywd4rXV1dISEhcrncYDDAI83NzdnZ2e870822icFgePDgwbFjx/bs2RMREfH69ev3V7zNUlBQsOe3FBQUKJXKrb0fIRqnu7v7+++/f/XqlbvKSR6cp0+ffvr0qYsnvnr16rvvvjtx4sSTJ0++//777u7ugoKCgoICt5QKjsAtlGq3oVQQuVyuTqdzMT3R0a9evYKt6npehYWFT548afstra2tZWVlx48f/3//7/99/fXXSqWytbW1za0kJCQolUrnaZ48eVJYWLilJkR8SDhTaK1We/DgwUOHDgmFwqampqamJqFQeOjQoYMHD27Zkg4ICGhtbS0qKtLr9Wq1uq6ujjju+kX6+/svXbrU3NxMHPkdFHpwcFAsFj9//nwL53Z1dV24cOHs2bMtLS3wiHOFlkqljx492mJBSZlutk3gLNba2mowGBobG8ktvEtwV0e/vwFDDM7h4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3t7aurq5mZmd7e3r6+vtXV1eR1EmSF7u7uDg4O9vDw8PPza2xshMna2tr8/Py8vLxycnIuXry4s88TCAQCAZwrNIfDYbPZcP56+/ZtcnIyi8VKSUmBIj0/P89isTgcztYy1uv14eHhCQkJDx8+hPL84MGDuLi48PDw/v7+rV0TsrKycufOnbi4OIpRSNjQGIYJBILy8nKbzbayspKZmQnt7Ozs7KSkpMXFRQzDcnNzCeMbQrah1Wp1WFjY9PQ08Vccx5ubmzMyMmw22/DwcFhYmF6vxzDsypUrERER09PTk5OTkZGRExMTY2NjIpEIClJzc/ONGzcIIbHb7c3NzefPn+/t7d3aKjzXWVpaOnr0KJTno0ePLi0tbXjK3bt3W1tbDxw4sO8X2Gy24RccKbTdbq+trb148eLKyoper//yyy+bm5txHB8ZGUlJSZmbm8Nx/NmzZ1lZWfPz85GRkW/evIFXgK33448/4jg+OTkJnS4qlSokJGRychIAoFAo4MvvmZmZmJgY6Ieora212+1v376FzwREeQiFHhkZOXbsGGxho9EYGhqq0+ngQZ1OZ7fbGxsbv/zyS6TQCARix9nYhp6dnYU/3759m5KSAkV6aWnp1atXW7ahIe3t7SwWKzs7Gyp0VlYWi8Xa/pLg2dnZmJiYwsJCaD2Ts4MKPTs7KxAIrFYrPK7T6VJTU9fW1

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表