Ability is needed to capture styles of elements to ensure proper optimization #1892
Labels
[Plugin] Image Prioritizer
Issues for the Image Prioritizer plugin (dependent on Optimization Detective)
[Plugin] Optimization Detective
Issues for the Optimization Detective plugin
[Type] Enhancement
A suggestion for improvement of an existing feature
Sometimes the Intersection Observer doesn't provide all of the information needed in order to perform optimizations. For example, images which have
visibility:hidden
,display:none
, oropacity:0
should in theory getfetchpriority=low
when they are in the initial viewport per #1587, but these won'tConversely, from #1308 (comment), images which are inside of elements which have
content-visibility:auto
will have a zeroed-outboundingClientRect
which Image Prioritizer then interprets as being in the initial viewport (since theboundingClientRect.top
of0
is less thanviewport.height
) and so they are gettingfetchpriority=low
when they should actually getloading=lazy
.These issues should perhaps have a way to efficiently query the computed style of certain elements to store their properties with the element in URL Metrics. There could be an async
getComputedStyle
function exported to theinitialize
andfinalize
async functions in extensions which could include some additional performance safeguards, like returning aPromise
that involvesrequestAnimationFrame()
or maybe even firstrequestIdleCallback()
. CallinggetComputedStyle()
can trigger a layout calculation (reflow), so we need to be careful to not negatively impact the performance of the page.I put together a Codepen that shows what Intersection Observer reports for various scenarios: https://codepen.io/westonruter/pen/zxYoNJP?editors=1111
Notice importantly that elements with
visibility:hidden
andopacity:0
are considered fully visible as far as Intersection Observer is concerned, leading to them not gettingfetchpriority=low
. And notice how the element withcontent-visibility:auto
has aboundingClientRect
with zeroed out values, leading it to not getloading=lazy
by Image Prioritizer.In addition to the possibility of a new JS API, we should extend the element schema to include a
computedStyle
object. In fact, let's say instead ofgetComputedStyle()
there was acaptureElementStyles()
function passed toinitialize
andfinalize
. It could take two args: the XPath of the element and an array of the styles properties to capture from the computed style. This could then automatically extend thecomputedStyle
object of the element. Since thecomputedStyle
object would be a core property it would not be available forextendElementData()
to override. Image Prioritizer should do the computed style capturing should be done duringinitialize
, since we want to know whether an image is visible up front.The text was updated successfully, but these errors were encountered: