close
PageSpeed Insights
- Google 用來測試網頁速度的工具,會影響到 Google 搜尋時的排序
- 檢測後的報告會提供一些修改的方向,但最簡單
粗暴的方式是直接安裝 Google 提供的 mod: modpagespeed
PageSpeed Modules
- 提供 Apache 與 Nginx 二種目前最受歡迎的 HTTP Server,另外下載時還要注意機器是 32-bit/64-bit
Installation
- ubuntu 可以透過 deb 快速安裝,之後重啟 HTTP Server 預設就會啟用;以下以 Apache Debian/Ubuntu 64-bit 為範例
# 下載 deb
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_amd64.deb
# 安裝
sudo dpkg -i mod-pagespeed-stable*.deb
# 重啟 apache2
sudo service apache2 restart
- 相關設定擋在 /etc/apache2/mods-available/pagespeed.conf,詳細設定可以參考apache加速模块mod_pagespeed的安装
其他可以提高分數的方法
清除前幾行內容中的禁止轉譯 JavaScript 和 CSS
- 移動 JavaScript 的位置從 head 到 body
- 要注意一些 lib(e.g. jQuery) 還是要在有引用到的 JavaScript 之前
使用瀏覽器快取功能
- 開啟 apache2 mod expires
sudo a2enmod expires
sudo service apache2 restart
- 修改網站的 .htaccess,加入 mod_expires 設定
ExpiresActive on
ExpiresDefault A86400
ExpiresByType image/x-icon A7776000
ExpiresByType application/x-javascript A604800
ExpiresByType application/javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/plain A86400
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType video/x-flv A2592000
ExpiresByType application/pdf A2592000
ExpiresByType text/html A3600
ExpiresByType application/x-font-woffl A7776000
ExpiresByType application/vnd.ms-fontobject A7776000
ExpiresByType image/svg+xml A7776000
文章標籤
全站熱搜