前言介紹
- 這款 WordPress 外掛「Menu Caching」是 2022-03-04 上架。
- 目前有 700 個安裝啟用數。
- 上一次更新是 2024-12-04,距離現在已有 150 天。
- 外掛最低要求 WordPress 5.3 以上版本才可以安裝。
- 外掛要求網站主機運作至少需要 PHP 版本 7.4 以上。
- 有 4 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
theogk |
外掛標籤
caching | menu cache | menu caching | speed up menu | wordpress menu |
內容簡介
所有人都知道,在 WordPress 中數據庫調用是主要的性能瓶頸。然而,大多數人不知道的是,WordPress 菜單在性能方面是多麼“昂貴”。
這個外掛將緩存菜單 HTML 並將緩存版本顯示給訪問者,從而使您的數據庫免於過多不必要的調用。
菜單數據散落在六個不同的數據庫表中。當用戶訪問一個頁面時,一個繁瑣的數據庫搜索開始進行。
在 "wp_terms"、"wp_term_taxonomy" 和 "wp_options" 表中,我們會找到菜單 ID、slug 和主題位置。然後在 "wp_posts" 和 "wp_postmeta" 中查找菜單的導航項目及其元數據。
在元數據中,我們將找到其目標對象,因此讓我們再次拜訪 "wp_terms" 或 "wp_posts" 來查找菜單項目的目標,並在 "wp_termmeta" 中查找其元數據。
這些是很多表格,甚至更多的數據庫搜索!當收集到所有需要的數據時,菜單 HTML 將被創建並顯示給用戶。
對於頁面上的每個菜單都要重複這個過程。桌面菜單、移動端菜單、頁腳上的某些菜單、標題欄右側購物車圖標旁邊的客戶帳戶菜單等等菜單。
想象一下,所有這些菜單,其中一些包含數十年的菜單項目,對於您站點上的每個訪問者,在每個頁面上加載。
菜單更改非常少,這使得它們易於緩存。緩存生成的菜單 HTML 將防止所有這些不必要的數據庫搜索,大大提高頁面加載速度。
完整功能列表:
緩存所有 WordPress 菜單以改善頁面加載時間。
按菜單啟用/禁用緩存。
在設置頁面上添加一個按鈕以清除所有菜單緩存。
每次編輯菜單時,其緩存都會自動清除。
所有緩存數據每隔 10 小時自動清除以保持所有項目的最新狀態,例如 Nonces 等。
與 WPRocket、W3 Total Cache 等緩存插件兼容。
與大多數翻譯插件兼容。已使用 WPML 和 TranslatePress 測試正常。
作用方式:
每次用戶訪問具有菜單的頁面時,WordPress 從數據庫中收集所有菜單數據,然後運行 walker 創建菜單的 HTML。在向用戶返回生成的 HTML 之前,將 HTML 保存在數據庫中以緩存。
下次用戶請求此特定菜單時,將返回保存的 HTML,而不是從頭創建菜單。
測試結果-它到底有多有效?
如果您使用了良好的緩存插件並且某個頁面是從緩存中提供的,則不會看到加載時間的差異。但是,在許多情況下,頁面沒有從緩存中提供,並且在這種情況下,您將會注意到巨大的差別。
頁面沒有從緩存中提供的一些情況:
如果您未使用頁面緩存插件(為什麼不使用?請安裝一個!)。
請求頁面沒有現有的緩存版本。在保存緩存版本之前,您在每個頁面上的第一次請求中受益於菜單緩存。
當用戶登錄時。即使使用每個用戶的緩存來為已登錄用戶創建緩存文件,菜單緩存仍然非常有用,因為緩存文件正在創建。
在電子商務站點上,不能按默認方式緩存的頁面,例如購物車、結算、我的帳戶、願望清單等頁面。
在大多數電子商務站點上,當客戶將物品添加到購物車時,為了防止迷惑的小購物車中出現錯誤數據,停止從緩存中提供頁面。
在某些 AJAX 請求中加載頁面內容,該內容包含菜單。在這種情況下,每個 AJAX 請求都需要調用菜單。
原文外掛簡介
We all know that database calls are the main performance bottleneck in WordPress. What most people don’t know though, is how “expensive” in terms of performance the WordPress menus are.
This plugin will cache the menu HTML and show the cached version to your visitors, saving your database from far too many unnecessary calls.
Menu data are scattered across six(!) different database tables. When a user visits a page, an odyssey throughout the database begins.
In ‘wp_terms’, ‘wp_term_taxonomy’ and ‘wp_options’ tables we’ll find menu ID, slug and theme location. Then ‘wp_posts’ and ‘wp_postmeta’ to find menu’s nav items and their metas.
In the metas, we will find its targeted object, so let’s pay ‘wp_terms’ or ‘wp_posts’ a visit again to find the menu item’s target and ‘wp_termmeta’ to find its metas.
These are a lot of tables and even more database calls! When all required data is collected, the menu HTML is created and it is shown to the user.
The same process is repeated for every menu on the page. Desktop menu, mobile menu, some menus on the footer, a menu for the customer account on the header’s right next to the cart icon…
Imagine all these menus, some of them with decades of menu items, loading in every page for every visitor on your site.
Menu changes are very rare and this makes them an easy target for caching. Caching the generated menu HTML will prevent all these unnecessary database calls and greatly improve page loading times.
Full features list
Caches all classic WordPress menus to improve page loading time.
Enable/disable caching per menu.
Clear all menu cache with a button on the settings page.
Every time you edit a menu, its cache is automatically purged.
All cached data are automatically purged every 10 hours to keep everything fresh, like nonces etc.
Compatible with caching plugins like WPRocket, W3 Total Cache etc.
Compatible with most translation plugins. Tested ok with WPML and TranslatePress.
How it works
Everytime a user visits a page with a menu, WordPress collects all menu data from the database, and then runs a walker to create the menu’s HTML. Right before this generated HTML is returned to the user, the HTML is saved in the database in a transient.
Next time a user requests this specific menu, the saved HTML will be returned, instead of creating the menu from scratch.
Test results – How effective is it anyway?
If you use a good caching plugin and a certain page is served from cache, then you not see a difference in loading times. BUT… there are many cases when a page is not served from cache and it that scenario you will notice a huge difference.
Some of the scenarios when a page is not served from cache:
If you are not using a page caching plugin (Why not? Please install one!).
No existing cached version exists of the requested page. You benefit from menu caching during the first page load on every page, before the cached version is saved.
When users are logged-in. Even when using a per-user cache for logged-in users, menu caching is still super useful to quickly create the menu as the cache files are getting created.
On e-commerce sites on pages that can’t be cached by default, like cart, checkout, my account, wishlist etc.
In most e-commerce sites, when a customer adds something to cart, then serving pages from cache stops to prevent false data in the mini-cart.
On some AJAX requests that load page content that includes menus.
Let’s see the results from some tests run on a medium-to-large e-commerce site with a mega menu with many categories, a separate mobile menu and a couple more small menus.
For admin user:
Loading time for all menus – no menu caching: 0.46s (in average)
Loading time for all menus – with menu caching: 0.0015s (in average)
Speed benefit: 300+ times faster – menu loads almost instantly!
For incognito visitor:
Loading time for all menus – no menu caching: 0.232194 sec
Loading time for all menus – with menu caching: 0.001185 sec
Speed benefit: ~200 times faster – menu loads almost instantly!
Of course these numbers depend on your WordPress installation, your server setup and so many parameters but the outcome will be the same.
With menu caching, instead of building the menu everytime and losing precious time during page load, your menus will load instantly from cache.
Compatibility with new “block” themes
Menus on the new block themes are constructed in a different way via the block editor, and not via the classic nav builder we all love to hate. This plugin can’t optimize menus built with the new block editor. It’s not going to break anything though, it won’t do anything at all. If you use a classic theme like 99.9% of the WordPress websites out there, this plugin will be useful to you.
Roadmap
This plugin does only one specific thing, menu caching. There is no plan to add more features. Of course small improvements may be implemented, and if any bug appears, I will try to fix it. Next versions will try to expand compatibility with more popular themes.
A next update is already under development, intending to add compatibility with Woodmart theme.
If you have any good ideas about this plugin and yoy want to contribute, you can make a PR in the github repo.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Menu Caching」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
1.1 | 1.0.0 | 1.1.1 | 1.1.2 | 1.1.3 | 1.1.4 | trunk |
延伸相關外掛(你可能也想知道)
暫無相關外掛推薦。