問題描述
我在谷歌速度測試中遇到關於我的指令碼中的查詢字串的遲到。所以,我試圖透過傳遞 false 作為引數的引數來刪除它們。但是,它似乎沒有效果:
wp_register_script('myscript', get_bloginfo('template_directory').'/scripts.myversionnumber.js',false,false,true);
wp_enqueue_script('myscript');
PS:js 檔名的”myversionnumber” 部分是我控制快取/版本控制的手段,而不是顯示出一些代理伺服器 (根據 Google pagepeed 測試) 的?ver =方法:
Remove query strings from static resources Enabling public caching in the HTTP headers for static resources allows the browser to download resources from a nearby proxy server rather than from a remote origin server. Learn more
Suggestions for this page
Resources with a “?” in the URL are not cached by some proxy caching servers. Remove the query string and encode the parameters into the URL for the following resources:
最佳解決方案
我認為你必須傳遞 NULL 作為第 4 個引數。
wp_register_script(
'myscript',
get_bloginfo('template_directory').'/scripts.myversionnumber.js',
false,
NULL,
true);
wp_enqueue_script('myscript');
次佳解決方案
您可以將 null 作為版本值傳遞給 wp_register_script 或 wp_enqueue_script,它應該丟棄查詢字串。
<?php
wp_enqueue_script(
'myscript',
'/path/to/script.js',
array(),
null
);
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。