外掛說明
This plugin’s purpose is to optimize the performance of embeds in WordPress, such as Tweets, YouTube videos, TikToks, and others.
目前能完成的最佳化項目如下:
- 僅在嵌入內容進入檢視區前才延遲載入嵌入內容。
- 在初始化檢視區前新增嵌入內容的預先連線連結。
- 為調整大小的嵌入內容保留空間以減少版面配置移位。
Lazy loading embeds improves performance because embeds are generally very resource-intensive, so lazy loading them ensures that they don’t compete with resources when the page is loading. Lazy loading of IFRAME
-based embeds is handled simply by adding the loading=lazy
attribute. Lazy loading embeds that include SCRIPT
tags is handled by using an Intersection Observer to watch for when the embed’s FIGURE
container is going to enter the viewport and then it dynamically inserts the SCRIPT
tag.
This plugin also recommends that you install and activate the Optimization Detective plugin, which unlocks several optimizations beyond just lazy loading. Without Optimization Detective, lazy loading can actually degrade performance when an embed is positioned in the initial viewport. This is because lazy loading such viewport-initial elements can degrade LCP since rendering is delayed by the logic to determine whether the element is visible. This is why WordPress Core tries its best to avoid lazy loading IMG
tags which appear in the initial viewport, although the server-side heuristics aren’t perfect. This is where Optimization Detective comes in since it detects whether an embed appears in any breakpoint-specific viewports, like mobile, tablet, and desktop. (See also the Image Prioritizer plugin which extends Optimization Detective to ensure lazy loading is correctly applied based on whether an IMG is in the initial viewport.)
When Optimization Detective is active, it will start keeping track of which embeds appear in the initial viewport based on actual visits to your site. With this information in hand, Embed Optimizer will then avoid lazy loading embeds which appear in the initial viewport. Furthermore, for such above-the-fold embeds Embed Optimizer will also add preconnect links for resources known to be used by those embeds. For example, if a YouTube embed appears in the initial viewport, Embed Optimizer with Optimization Detective will omit loading=lazy
while also adding a preconnect link for https://i.ytimg.com
which is the domain from which YouTube video poster images are served. Such preconnect links cause the initial-viewport embeds to load even faster.
The other major feature in Embed Optimizer enabled by Optimization Detective is the reduction of layout shifts caused by embeds that resize when they load. This is seen commonly in WordPress post embeds or Tweet embeds. Embed Optimizer keeps track of the resized heights of these embeds. With these resized heights stored, Embed Optimizer sets the appropriate height on the container FIGURE element as the viewport-specific min-height
so that when the embed loads it does not cause a layout shift.
Since Optimization Detective relies on page visits to learn how the page is laid out, you’ll need to wait until you have visits from a mobile and desktop device to start seeing optimizations applied. Also, note that Optimization Detective does not apply optimizations by default for logged-in admin users.
Please note that the optimizations are intended to apply to Embed blocks. So if you do not see optimizations applied, make sure that your embeds are not inside of a Classic Block.
這個外掛設計成不須進行組態便能執行,因此目前不須進行任何設定,也沒有使用者介面。
安裝方式
自動安裝
- 前往 [外掛]→[安裝外掛]。
- 搜尋「Embed Optimizer」。
- 安裝並啟用 Embed Optimizer 外掛。
手動安裝
- 將外掛安裝壓縮檔解壓縮所得的
embed-optimizer
資料夾上傳至網站的/wp-content/plugins/
目錄中。 - 前往 [外掛] 頁面。
- 啟用 Embed Optimizer 外掛。
常見問題集
-
使用者可以在何處提交外掛意見反應?
-
非常鼓勵也感謝使用者提供意見反應,尤其是這個外掛會是將來 WordPress 核心程式的功能。使用者如果有任何建議或功能要求,可以在 WordPress 效能團隊的 GitHub 存放庫提出。如果對這個外掛有需要疑難排解協助或提出問題之處,請在外掛的技術支援論壇提出。
-
在何處可以回報安全性程式碼錯誤?
-
效能團隊及 WordPress 社群對安全性程式碼錯誤一向嚴陣以待,我們非常感謝使用者披露相關發現所付出的心力,並會盡全力解決使用者提出的問題。
如需回報安全性問題,請參考 WordPress HackerOne 計畫。
-
如何為這個外掛做出貢獻?
-
非常感謝各位的各種貢獻!請參考核心程式效能團隊手冊以進一步了解參與的方式。
外掛原始程式碼儲存於 WordPress/performance 在 GitHub 上的存放庫。
使用者評論
這個外掛目前沒有任何使用者評論。
參與者及開發者
變更記錄
0.4.0
Enhancements
- Incorporate media queries into preconnect links to account for whether embeds are in viewport. (1654)
- Serve unminified scripts when
SCRIPT_DEBUG
is enabled. (1643)
0.3.0
Enhancements
- Leverage URL Metrics to reserve space for embeds to reduce CLS. (1373)
- Avoid lazy-loading images and embeds unless there are URL Metrics for both mobile and desktop. (1604)
0.2.0
Enhancements
- Facilitate embedding of Embed Optimizer. (1337)
- Leverage Optimization Detective to optimize embeds in Embed Optimizer. (1302)
0.1.2
Enhancements
- Improve overall code quality with stricter static analysis checks. (775)
- Bump minimum PHP requirement to 7.2. (1130)
Bug Fixes
- Hide post embed iframes with visibility:hidden instead of clipping. (1192)
0.1.1
0.1.0
- Initial release.