前端集合 - 关注前端技术和互联网免费资源

关注前端技术和互联网免费资源

分类儿

页面儿

搜索儿

前端集合 RSS订阅
Home » 经验记录 » 如何为WordPress和Typecho设置静态资源缓存

如何为WordPress和Typecho设置静态资源缓存

发布者:前端集合 // 发布时间:2014-03-03 21:24:00 // 分类:经验记录 // 访问: 10,865 次 // 热度:

如何为WordPress和Typecho设置静态资源缓存

为什么要设置静态资源缓存(即浏览器缓存)?

在HTTP标头中为静态资源设置过期日期或最长存在时间,可指示浏览器从本地磁盘中加载以前下载的资源,而不是通过网络加载。这样, 网站加载速度会更快.

下面的代码都需要放到.htaccess中才能生效. 推荐设置过期时间为一个月, 即: max-age=2592000.

通过FilesMatch设置

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|css|js)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

通过mod_expires.c设置

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 months"
ExpiresByType text/html "access plus 1 months"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpeg "access plus 2 months"
ExpiresByType application/x-shockwave-flash "access plus 2 months"
ExpiresByType application/x-javascript "access plus 2 months"
</IfModule>

如需针对具体的资源类型需要这样:

ExpiresByType image/gif "access plus 5 hours 3 minutes"

更多规则参考Apache Module mod_expires.

参考来源:

Tags: wordpress静态资源缓存, typecho静态资源缓存, wordpress浏览器缓存, typecho浏览器缓存, 静态资源缓存, 浏览器缓存, wordpress cache expire, typecho cache expire

才发现Sublime Text的Project功能>>  << 浏览器上就可以玩的5个优秀格斗小游戏
Top