A-A+

wordpress站点开启浏览器缓存教程

2016年07月04日 WordPress 暂无评论 阅读 212 次浏览 次

开启浏览器缓存是指访客第一次访问时下载的css和js文件存放在访客本地电脑,当访客第二次访问网站时,浏览器无需下载css和js文件,直接调用本地css和js文件,加快了网页的加载。

 

Speeding-up-WordPress-with-Leverage-Browser-Caching2

Apache服务器开启浏览器缓存的办法

LAMP服务器上,编辑网站根目录下的.htaccess文件,加上如下内容:

## EXPIRES CACHING ##

ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 days"

## EXPIRES CACHING ##

这就基本上缓存了大部分较大的文件。

Nginx服务器开启浏览器缓存的办法

在网站的配置文件bo.moioi.com.conf里的location段编辑成如下的内容:

location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 365d;
    }location ~*  \.(pdf)$ {
        expires 30d;
}
然后重启nginx服务service nginx restart,大功告成。

wordpress网站启用浏览器缓存可以提高google pagespeed test的分数。

 

标签:

评论已关闭!

Copyright © 香港虚拟主机_美国虚拟主机_香港服务器_美国服务器租用托管 保留所有权利.   Theme  Ality 蜀ICP备14006632号-1

用户登录