找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1696|回复: 1

[Wordpress] 设置浏览器缓存提高wordpress访问速度

[复制链接]
发表于 2012-10-24 22:58:42 | 显示全部楼层 |阅读模式
本帖最后由 小马哥 于 2012-10-24 23:03 编辑

谷歌推荐设置浏览器缓存(Leverage browser caching)来提高网站的访问速度,那么对于wordpress网站来说,该怎样进行设置?下面是我在国外网站上找到的方法:

We should always be looking for ways to improve the functionality of our blogs. One of the easiest ways to improve our blog functionality and speed is to leverage browser caching. Another way of saying this is that we add expires or cache control headers for our blog. In Layman’s terms, by leveraging browser caching, we can reduce the number of HTTP requests that the server needs to process, thus reducing loading times and improving user experience and website performance. And as an added bonus, when we leverage browser caching, we improve our scores on PageSpeed and YSlow! In order to do this, we will need to modify our .htaccess file and add in the appropriate directives.

我们应该不断寻找方法改进自己博客的性能。提高博客性能的最容易的方法之一便是使用浏览器缓存加速WordPress访问速度。 通常,网站上的静态内容,诸如:图片、CSS、JS、flash等,一般变动很小,甚至几个月都不会有所更改,这些体积庞大的静态内容占据了大部分网页加载时间。优化设置浏览器端缓存(Leverage browser caching),可以有效减少HTTP 请求服务器消耗的时间,进而提速自己的博客,改善用户的体验,并在PageSpeed和Yslow上获取高分。所谓缓存(cache)简单的说,就是浏览器将从服务器端收到的数据缓存起来,在下次浏览器再次需要这些数据的时候,就可能直接使用缓存的数据,而不需要重新再从服务器端下载了。实现方法也很简单,向.htaccess(推荐用ftp把.htaccess文件下载到本地,修改后再上传)文件中加入如下代码:
  1. ## EXPIRES CACHING ##
  2. <IfModule mod_expires.c>
  3. ExpiresActive On
  4. ExpiresByType image/jpg "access 1 year"
  5. ExpiresByType image/jpeg "access 1 year"
  6. ExpiresByType image/gif "access 1 year"
  7. ExpiresByType image/png "access 1 year"
  8. ExpiresByType text/css "access 1 month"
  9. ExpiresByType application/pdf "access 1 month"
  10. ExpiresByType text/x-javascript "access 1 month"
  11. ExpiresByType application/x-shockwave-flash "access 1 month"
  12. ExpiresByType image/x-icon "access 1 year"
  13. ExpiresDefault "access 2 days"
  14. </IfModule>
  15. ## EXPIRES CACHING ##
复制代码
1 year = 1年
1 month = 1月
2 days = 2天

英文原文地址:http://thomasgriffinmedia.com/blog/2010/11/how-to-leverage-browser-caching-in-wordpress-via-htaccess/
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|王牌互联

GMT+8, 2024-12-21 04:08 , Processed in 0.028298 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表