Module Proposal: Alternative LCP Optimization (via Output Buffering) #805
Labels
[Focus] Images
Issues related to the Images focus area
[Plugin] Optimization Detective
Issues for the Optimization Detective plugin
[Type] (Legacy) Module Proposal
A new module proposal (legacy)
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: