
內容簡介
“重要的是要使資源(圖像、腳本、樣式表等)具有緩存功能。”
Steve Souders
使用 CDN 沒有查詢字串參數要簡單得多。
此外掛僅修改本機資源的 URL。
ver 查詢字串參數將插入檔案名稱中。
例如 jquery.min.js?ver=1.10 將變成 jquery.min.110.js。
若要在 Web 伺服器中反轉此操作,請在 Nginx 設定檔中加入此行:
server {
location ~ ^(.+)\.\d\d+\.(js|css|png|jpg|jpeg|gif|ico)$ {
#try_files $uri $1.$2 /index.php?$args;
try_files $uri $1.$2 =404;
}
}
或在 Apache 設定或 .htaccess 檔案中加入。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.\d\d+\.(js|css|png|jpg|jpeg|gif|ico)$ $1.$2 [NC,L]
在實際使用之前測試插件
您可以將兩個 add_filter() 呼叫替換為以下內容來測試此插件:
require_once( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/wp-load.php' );
wp();
echo o1_revving_src( $argv[1] ) . PHP_EOL;
然後從命令列介面啟動它:php revving.php <TEST-URL>
連結
此插件的開發在 GitHub 上進行。
外掛標籤
開發者團隊
原文外掛簡介
“It’s important to make resources (images, scripts, stylesheets, etc.) cacheable.”
Steve Souders
It is much easier to use a CDN without Query String Parameters.
This plugins alters only local resources’ URL-s.
The ver Query String Parameter will be inserted into the filename.
For example jquery.min.js?ver=1.10 becomes jquery.min.110.js.
To reverse this in the web server add this line to your nginx config:
server {
location ~ ^(.+)\.\d\d+\.(js|css|png|jpg|jpeg|gif|ico)$ {
#try_files $uri $1.$2 /index.php?$args;
try_files $uri $1.$2 =404;
}
}
Or to your Apache configuration or .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.\d\d+\.(js|css|png|jpg|jpeg|gif|ico)$ $1.$2 [NC,L]
Testing the plugin before live usage
You can test the plugin by replacing the two add_filter() calls with this
require_once( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/wp-load.php' );
wp();
echo o1_revving_src( $argv[1] ) . PHP_EOL;
Then start it from CLI: php revving.php
Links
Development of this plugin goes on on GitHub.
