You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disable core's insertion of fetchpriority="high" and loading="lazy" attributes during template rendering to instead insert them on the fully-rendered template captured via output buffering. The module would explore whether this is feasible and whether it produces better results.
Scope
Add output buffering of the template in a similar way as Server-Timing is doing already. A separate output buffer can be used specific for this module without needing to reuse the one from Server-Timing.
Introduce a filter in the output buffer callback. This would be implementing Core-43258 which could be reused by plugins seeking to do optimizations or by caching plugins to store the rendered page.
Use WP_HTML_Tag_Processor to iterate over the HTML document and inject the fetchpriority="high" and loading="lazy" attributes. This may involve the use of bookmarks to gather up a set of candidates, also informed by existing heuristics during template generation.
Rationale
WordPress currently optimized LCP elements by injecting fetchpriority="high" and omitting loading="lazy" during template rendering. This has been the only option available for core because core lacks any standardized mechanism for output buffering and filtering the output of the page, even though a multitude of plugins do so (including the Performance Lab plugin to do Server-Timing).
As noted in #793, there are currently some cases where the optimization attributes are not applied correctly, due to the complex and varied mechanisms that WordPress core and plugins use to render templates. Some themes and plugins may even hard-code img tags in which case it is currently impossible to apply the correct attributes.
If the rendered template were output buffered, then the optimization attributes could be applied once on the entire document before the complete HTML page is returned to the user.
Note that block themes are already essentially output buffered, although without using ob_start().
The text was updated successfully, but these errors were encountered:
Overview
About the module
Purpose
Disable core's insertion of
fetchpriority="high"
andloading="lazy"
attributes during template rendering to instead insert them on the fully-rendered template captured via output buffering. The module would explore whether this is feasible and whether it produces better results.Scope
WP_HTML_Tag_Processor
to iterate over the HTML document and inject thefetchpriority="high"
andloading="lazy"
attributes. This may involve the use of bookmarks to gather up a set of candidates, also informed by existing heuristics during template generation.Rationale
WordPress currently optimized LCP elements by injecting
fetchpriority="high"
and omittingloading="lazy"
during template rendering. This has been the only option available for core because core lacks any standardized mechanism for output buffering and filtering the output of the page, even though a multitude of plugins do so (including the Performance Lab plugin to do Server-Timing).As noted in #793, there are currently some cases where the optimization attributes are not applied correctly, due to the complex and varied mechanisms that WordPress core and plugins use to render templates. Some themes and plugins may even hard-code
img
tags in which case it is currently impossible to apply the correct attributes.If the rendered template were output buffered, then the optimization attributes could be applied once on the entire document before the complete HTML page is returned to the user.
Note that block themes are already essentially output buffered, although without using
ob_start()
.The text was updated successfully, but these errors were encountered: