Preconnect to domains of resources for LCP elements known to be in embeds when in initial viewport #1058
Labels
[Plugin] Embed Optimizer
Issues for the Embed Optimizer plugin (formerly Auto Sizes)
[Plugin] Optimization Detective
Issues for the Optimization Detective plugin
[Type] Enhancement
A suggestion for improvement of an existing feature
Feature Description
When an embed is the LCP element, we can optimize its loading (beyond omitting
loading=lazy
cf. #1054) by adding preconnect links to domains for resources which are known to be present in the iframe, especially for the LCP element in the iframe.YouTube Embeds
A YouTube embed loads resources from the following domains (see on trace.cafe):
fonts.gstatic.com
(for the fonts used in the title)yt3.ggpht.com
(for the channel logo)i.ytimg.com
(for the poster image)www.youtube.com
(for JS and CSS assets)www.gstatic.com
(for more JS assets)Note that the actual LCP element and the perceived LCP element on YouTube are not the same due to limitations in the definition of LCP heuristics (h/t @tunetheweb):
Bullet point two is problematic for YouTube embeds. Chrome is detecting this element to be LCP:
But the percieved LCP element is the poster image which is background:
However, since it is a background image which covers the full viewport, it is excluded from being considered the LCP element.
So this introduces a bit of a conundrum. For the sake of YouTube embeds, do we add a preconnect for
fonts.gstatic.com
so the actual LCP element renders sooner, or do we preconnecti.ytimg.com
so that the perceived LCP element renders sooner? I guess for now the answer is both, at least until browsers improve on these heuristics to match user expectations.Other Embeds
A similar analysis should be done for other embeds.
Implementation
This issue is tagged for both Embed Optimizer and the Optimization Detective plugins. The latter should expose an API so that the former can discover an initial viewport embed and then be able to add the preconnects.
See also ampproject/amp-toolbox-php#10 (from 5+ years ago!) which proposed doing this similarly for AMP components for embeds. Note that AMP components are designed to be able to preconnect to relevant domains when initialized. For example, the
amp-youtube
component preconnects tohttps://s.ytimg.com
andhttps://i.ytimg.com
(the former seems obsolete which I've proposed removing in ampproject/amphtml#39903). Nevertheless, when the embed is in the initial viewport, preconnecting when the component is rendered is almost too late, and the preconnect links should have rather been added to the HTML so they don't depend on JS to execute. This is what the amp-toolbox-php issue was for, and we can do the same for plain HTML.The text was updated successfully, but these errors were encountered: