[WordPress] 外掛分享: W3TC Minify Helper

首頁外掛目錄 › W3TC Minify Helper
全新外掛
安裝啟用
尚無評分
2583 天前
最後更新
問題解決
WordPress 5.0+ PHP 7.0+ v1.0.0.1 上架:2019-02-13

內容簡介

這是一個 W3 Total Cache 外掛的輔助工具,它會產生一個 W3TC JSON 配置檔,可用於匯入至 W3TC 中。

W3TC 的自動縮小模式在我的網站上無法正常運作。問題在於使用自動縮小模式的 JavaScript 檔案順序與未縮小的順序不同。這導致 JavaScript 函數錯誤未定義。W3TC 提供了手動設置 JavaScript 檔案順序的幫助工具,但我認為這個工具很麻煩。我只想要和未縮小的檔案順序相同。因此,我撰寫了這個外掛程式。

此外掛需要了解您的網站使用的 JavaScript 檔。每個網頁視圖都會為該網頁的範本設置有序的 JavaScript 檔案清單。如果這個有序清單已更改,則會通過修改當前 W3TC 配置的「minify.js.groups」字段的值,以與該清單相容,生成一個新的 W3TC 配置檔。這個過程是累積的,因此在為每個範本查看代表性網頁後,將生成完整的 W3TC 配置檔。此外,如果稍後模板的有序 JavaScript 檔案列表更改,則這也會產生一個新的相容的 W3TC 配置檔。

註:W3TC 假設模板的有序 JavaScript 檔案清單是固定的。如果您的網頁動態計算 JavaScript 檔案,並且使用相同模板的兩個不同網頁計算不同的 JavaScript 檔案清單,則 W3TC 無法用於縮小這些 JavaScript 檔案。此外,手動縮小模式的 W3TC 只能看到活動佈景主題目錄中的範本檔案。但是,使用「template_include」過濾器,外掛可以強制 WordPress 載入外掛目錄中的範本,而不是佈景主題目錄中的範本。手動縮小模式的 W3TC 不能用於縮小放在外掛目錄中的範本的 JavaScript 檔案。

此外掛生成的新 JSON 配置檔可以下載,進一步編輯以微調縮小過程,並重新匯入至 W3TC。下載連結位於「已安裝的外掛」管理頁面,在「停用」連結後。但是,在匯入此新配置檔至 W3TC 之前,應該下載目前的 W3TC 配置,以便在新配置失效時恢復當前配置。此外,在將新配置檔匯入至 W3TC 之前,應該對比新配置檔和當前配置檔,以驗證新配置檔是否有明顯的錯誤。並檢查「minify.js.groups」部分,以確認每個範本都有一個條目,以驗證配置是否完整。

註:如果要使用此外掛程式生成的有序 JavaScript 檔案清單,W3TC 的「縮小模式」必須設置為「手動」。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「W3TC Minify Helper」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This is a helper plugin for the W3 Total Cache plugin. It generates a W3TC JSON configuration file that can be imported into W3TC.
The W3TC auto minify mode does not work on my web site. The problem is the order of the JavaScript files using the auto minify mode is different from the order without minification. This results in undefined JavaScript function errors. W3TC has a help tool for manually setting the order of JavaScript files. I think this tool is tiresome to use. I just want to have the same order as without minification. So, I wrote this plugin to do this.
This plugin needs to learn about the JavaScript files that your website uses. Every view of a web page sets the ordered list of JavaScript files for the template of that web page. If this ordered list has changed a new W3TC configuration file is generated by modifying the value of the field ‘minify.js.groups’ of the current W3TC configuration to be compatible with the new ordered list of JavaScript files for that template. This process is cumulative so after viewing a representative web page for each template a complete W3TC configuration file will be generated. Further, if some time later the ordered list of JavaScript files for a template changes then this will also generate a new compatible W3TC configuration file.
N.B. – W3TC assumes that the ordered list of JavaScript files for a template is fixed. If your web pages are dynamically computing the JavaScript files and two different web pages using the same template compute different lists of JavaScript files then W3TC cannot be used to minify those JavaScript files. Also, W3TC in manual minify mode only sees the template files in the active theme directory. However, using the ‘template_include’ filter a plugin can force WordPress to load a template in the plugin’s directory instead of a template in the theme’s directory. W3TC in manual minify mode cannot be used minify the JavaScript files of templates in plugin directories.
The new JSON configuration file generated by this plugin can be downloaded, further edited to fine tune the minify process and imported back into W3TC. The download link is on the “Installed Plugins” admin page after the “Deactivate” link. But, before you import this new configuration file into W3TC, you should download the current configuration of W3TC so that you can restore the current configuration if the new configuration does not work. Also, before importing the new configuration file into W3TC you should diff the new configuration file against the current configuration file to verify that the new configuration file has no obvious errors. You should also verify that you have a complete configuration by viewing the ‘minify.js.groups’ section and checking that there is an entry for each of your templates.
N.B. – W3TC “Minify mode” must be set to “Manual” for W3TC to use the ordered list of JavaScript files generated by this
plugin.

延伸相關外掛

文章
Filter
Mastodon