開啓瀏覽器緩存是指訪客第一次訪問時下載的 css 和 js 文件存放在訪客本地電腦,當訪客第二次訪問網站時,瀏覽器無需下載 css 和 js 文件,直接調用本地 css 和 js 文件,加快了網頁的加載。

Apache 服務器開啓瀏覽器緩存的辦法

LAMP 服務器上,編輯網站根目錄下的.htaccess 文件,加上如下內容:

## EXPIRES CACHING ##ExpiresActiveOnExpiresByType 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 的分數。