外掛說明
這個外掛支援能改進頁面在瀏覽器中的載入及轉譯效能的功能:
- 串連 CSS
- 串連 JavaScript
- Execution timing of non-critical scripts
- 注意事項:變更指令碼執行時機有其風險,而且並非全部網站均能展現效果。
測試方式
如需測試並未在全站啟用的功能,網站管理員可以將查詢參數附加至 WordPress 網站文章或頁面的網址。舉例來說,如需對 https://example.com/blog/ 測試啟用串連 JavaScript 後的結果,可以使用 https://example.com/blog/?concat-js=1 這個網址。
支援的查詢參數:
concat-css可以控制 CSS 串連。參數值1代表啟用而0代表停用。concat-js可以控制 JavaScript 串連。參數值1代表啟用而0代表停用。load-mode-js可以控制非關鍵 JavaScript 的載入。參數值 defer 是為了延遲載入,而 async 是為了非同步載入,其他參數值都代表停用這個功能。
PHPUnit (Docker)
You can run the PHPUnit tests locally using Docker (no local MySQL required).
First time (or after changing DB credentials):
docker compose down -v
Run tests:
docker compose up --build --abort-on-container-exit --exit-code-from tests
Optional overrides (examples):
WP_VERSION=6.5 docker compose up --build --abort-on-container-exit --exit-code-from testsPHP_VERSION=7.4 docker compose up --build --abort-on-container-exit --exit-code-from testsPHPUNIT_VERSION=9.6.20 docker compose up --build --abort-on-container-exit --exit-code-from tests
安裝方式
這個外掛使用合理的預設值,因此不需組態即可執行,但是網站管理員可以使用多個常數自訂組態。
PAGE_OPTIMIZE_CACHE_DIR
Page Optimize 預設能對串連的指令碼及樣式進行快取,而這個常數控制快取檔案的儲存位置。預設目錄為網站的 wp-content 資料夾中的 cache/page_optimize。
如需變更快取儲存位置,請將常數設定為指定位置在檔案系統中的絕對路徑。
如果要停用快取,請將這個常數設定為 false。請注意,除非網站管理員另行使用其他快取機制,否則停用 Page Optimize 的快取功能可能會對網站效能造成負面影響。
PAGE_OPTIMIZE_CSS_MINIFY
Page Optimize 具備 CSS 最小化的功能,但這項功能預設關閉。
如果網站使用快取功能,並且未在任何位置進行 CSS 最小化,建議將這個常數設定為 true 以啟用這項功能。
使用者評論
參與者及開發者
以下人員參與了開源軟體〈Page Optimize〉的開發相關工作。
參與者變更記錄
0.6.2
- Fix: Harden CSS concat
@importhoisting to preserve long Google Fonts-style URLs with semicolons and avoid false positives from@import-like substrings in rule bodies/URL paths.
0.6.1
- Fix: Skip JavaScript concatenation for scripts that request defer or async loading to preserve core loading behavior.
- Fix: Skip JavaScript concatenation for module scripts (type=”module”) and scripts whose tag is modified via the script_loader_tag filter (for example, plugins that add module attributes), improving compatibility.
0.6.0
- Fix: Preserve stylesheet enqueue/document order when concatenating CSS. Concat-eligible styles are now emitted as sequential runs and split around non-concatenated items (e.g. external/excluded/dynamic URLs), media changes, RTL handling, and other boundaries.
- Fix: Inline styles (wp_add_inline_style) now print immediately after their parent stylesheet, including when styles are concatenated.
- Fix: Apply core’s style_loader_tag filter when a concatenation run contains only a single stylesheet (matching core behavior and the JS-side fix from 0.5.0).
- Fix: The css_do_concat filter is now evaluated once per handle.
- Fix: The concat service no longer drops @import directives due to a closure scoping bug. (@charset/@import handling now runs against the intended pre-output buffer.)
- Fix: Stylesheets containing @import now start a new concat run so service-side @import hoisting cannot reorder imports ahead of earlier stylesheets.
- Fix: Treat @import and @charset as case‑insensitive when building concatenated CSS, preventing missed rules in some stylesheets.
0.5.8
- Update Tested Up To Version to 6.9.
0.5.7
- Update Tested Up To Version to 6.8.
0.5.6
- Update Tested Up To version to 6.7.
0.5.5
- Fix: Stop skipping inline scripts when src is empty.
0.5.4
- Bail when editing pages or posts in the Editor. Increased the max concatenated file limit.
0.5.1
- Bail when editing pages in Brizy Editor (it errors when JavaScript load mode is
async).
0.5.0
- Apply the
script_loader_tagfilter for scripts that are concatenate-able but have no neighbors to concatenate with. This fixes a case where the TwentyTwenty theme wanted to apply adeferattribute to its script but was never given the opportunity.
0.4.5, 0.4.6
- Force absolute paths for CSS replacements.
- Lower required PHP version to 7.0.
0.4.4
- Don’t queue the cache cleaning WP Cron job if we aren’t caching.
- Cleanup cache if we turned caching off or directory changed.
0.4.3
- gzip in PHP slows stuff down a bit. Simply don’t do this. Any web server can handle this better.
- also remove the output buffering, no need for that anymore
- CSS Minification can sometimes slow things down significantly. Add constant to enable/disable.
0.4.2
- Initial release. No changes yet. 🙂