內容簡介
使用瀏覽器快取,你可以告知瀏覽器你的文件通常何時更改,例如每個月、每個週等。這會加速你的網站,因為瀏覽器只會在指定的時間後向你的伺服器發出請求。PageSpeed 是 Google 排名因素,所以擁有快速的網站非常重要。
啟用瀏覽器快取有幾種方法。此外掛使用 Expires。以下程式碼將被添加到您的 .htaccess 檔案:
ExpiresActive On
ExpiresByType text/css “access plus 1 month”
ExpiresByType text/javascript “access plus 1 month”
ExpiresByType text/html “access plus 1 month”
ExpiresByType application/javascript “access plus 1 month”
ExpiresByType application/x-javascript “access plus 1 month”
ExpiresByType application/xhtml-xml “access plus 1 month”
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/x-icon “access plus 1 month”
第二行代表 CSS 檔案會在一個月後請求。第三行代表 JavaScript 檔案會在一個月後請求,以此類推。
當然,您可以更改週期。您將在常見問題解答區找到相關說明。
如果您沒有讀取 .htaccess 檔案的權限,您會收到 403 權限拒絕的錯誤頁面。因此,在啟用此外掛之前,請確保您有讀取 .htaccess 檔案的權限(通常您已有此權限)。
外掛標籤
開發者團隊
② 後台搜尋「Browser Caching with .htaccess」→ 直接安裝(推薦)
原文外掛簡介
With Browser Caching you can tell Browsers when your files usually change, e.g. every month, every week, etc. This will fasten up your website because Browser will only make requests to your Server after the declared time. PageSpeed is a Google Ranking Factor so it is important to have a fast website.
There a several ways to enable Browser Caching. This Plugin uses Expires. The following code will be added to your .htaccess file:
ExpiresActive On
ExpiresByType text/css “access plus 1 month”
ExpiresByType text/javascript “access plus 1 month”
ExpiresByType text/html “access plus 1 month”
ExpiresByType application/javascript “access plus 1 month”
ExpiresByType application/x-javascript “access plus 1 month”
ExpiresByType application/xhtml-xml “access plus 1 month”
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/x-icon “access plus 1 month”
The second line means that css files will be requested after 1 month. The third line means that javascript files will be requested after 1 month and so on.
Of course you can change the periods. You will find instructions for that in the FAQ section.
In case you do not have reading rights to the .htaccess file you will get a 403 Permission Denied Error Page. So before activating this Plugin make sure you have reading rights to the .htaccess file (normally you have those rights).
