静态的html页面想要设置使用浏览器缓存
来源:互联网 发布:java 线程面试题 编辑:程序博客网 时间:2024/06/06 01:50
设置html页面缓存方法:
静态的html页面想要设置使用缓存:
通过HTTP的META设置expires和cache-control
<
meta
http-equiv
=
"Cache-Control"
content
=
"max-age=7200"
/>
<
meta
http-equiv
=
"Expires"
content
=
"Mon, 20 Jul 2013 23:00:00 GMT"
/>
要在后台代码段,实现图片,css,js,flash的缓存
Response.AddHeader("cache-control","max-age=时间(单位:秒)")或Response.Expires=时间(单位:分)来启用缓存。如果用Response.AddHeader("expires","utc时刻")来设置Expires的话,cache-control的优先级比expires高,
就是说如果设置了cache-control,那么expires设置的值就被覆盖掉。如果是用Response.Expires设置的话就不受这个约束。
对网页中的图片或其他请求服务器端缓冲设置
apache静态文件缓存时间设置
如果要对文件添加cache可以通过apache的mod_expire模块,写法为
关于图片,css,js,flash的缓存
这个主要通过服务器的配置来实现这个技术,如果使用apache服务器的话,可以使用mod_expires模块来实现:
编译mod_expires模块:
Cd /root/httpd-2.2.3/modules/metadata
/usr/local/apache/bin/apxs -i -a -c mod_expires.c //编译
先打开httpd.conf文件,然后查找expires这个模块,找到后,删除左边的#号,表示打这个模块,并重启apache服务器
编辑httpd.conf配置:添加下面内容
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType text/html "access plus 1 months"
ExpiresByType text/css "access plus 1 months"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/jpg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
EXpiresByType application/x-shockwave-flash "access plus 1 months"
EXpiresByType application/x-javascript "access plus 1 months"
#ExpiresByType video/x-flv "access plus 1 months"
</IfModule>
解释:第一句--开启服务
第二句--默认时间是一个月
在下面是关于各种类型的资源的缓存时间设置
更详细的说明可以参考我的《网站优化--让你的网页飞起来》关于这个模块的使用介绍
参考资料:http://www.infoq.com/cn/articles/etags
http://www.lifetyper.com/archives/000087.html
http://developer.yahoo.com/performance/rules.html
http://www.websiteoptimization.com/speed/tweak/cache/
http://www.mnot.net/cache_docs/
- 静态的html页面想要设置使用浏览器缓存
- 设置html页面不让浏览器缓存的方法
- 设置html页面不让浏览器缓存的方法
- 设置html页面不让浏览器缓存的方法
- html页面调试设置不让浏览器缓存
- 浏览器页面的缓存设置(不缓存设置)
- thinkphp 静态缓存页面的设置方法
- 设置浏览器不缓存页面
- html页面的缓存与不缓存设置
- html jsp 禁止浏览器缓存页面
- HTML-浏览器不记住页面缓存
- 静态缓存案例生成一个html页面
- 静态页面html防止js加载缓存
- php页面静态化 获取页面缓存生成HTML页面
- 静态页面设置缓存、动态页面设缓存
- 设置浏览器不使用缓存
- .Html+Asp+asp.net(C#)禁止浏览器缓存页面的方法-禁止缓存
- WebView打开网页,设置支持Javascript,浏览的网页后退而不是退出浏览器,判断页面加载过程,缓存的使用
- 王学岗progressbar
- mybatis 中<if test="">test中的判断条件 ognl
- 在线速查手册。
- UVa 725 Division(暴力求解)
- git config
- 静态的html页面想要设置使用浏览器缓存
- Python 网络编程(套接字编程)
- generate-parentheses
- 使用 Git Bash 配置用户名和命令别名
- (Android网络4)Retrofit
- HDOJ HDU 1048 The Hardest Problem Ever
- <meta http-equiv="pragma" content="no-cache">属性http-equiv功能介绍
- eclipse下的UML妙用
- java String