-
Notifications
You must be signed in to change notification settings - Fork 152
Ability is needed to capture styles of elements to ensure proper optimization #1892
Copy link
Copy link
Open
Enhancement
0 / 20 of 2 issues completed
Copy link
Labels
[Plugin] Image PrioritizerIssues for the Image Prioritizer plugin (dependent on Optimization Detective)Issues for the Image Prioritizer plugin (dependent on Optimization Detective)[Plugin] Optimization DetectiveIssues for the Optimization Detective pluginIssues for the Optimization Detective plugin[Type] EnhancementA suggestion for improvement of an existing featureA suggestion for improvement of an existing feature
Milestone
Metadata
Metadata
Assignees
Labels
[Plugin] Image PrioritizerIssues for the Image Prioritizer plugin (dependent on Optimization Detective)Issues for the Image Prioritizer plugin (dependent on Optimization Detective)[Plugin] Optimization DetectiveIssues for the Optimization Detective pluginIssues for the Optimization Detective plugin[Type] EnhancementA suggestion for improvement of an existing featureA suggestion for improvement of an existing feature
Type
Fields
Give feedbackNo fields configured for Enhancement.
Projects
StatusShow more project fields
To Do 🔧
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:0should in theory getfetchpriority=lowwhen 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:autowill have a zeroed-outboundingClientRectwhich Image Prioritizer then interprets as being in the initial viewport (since theboundingClientRect.topof0is less thanviewport.height) and so they are gettingfetchpriority=lowwhen 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
getComputedStylefunction exported to theinitializeandfinalizeasync functions in extensions which could include some additional performance safeguards, like returning aPromisethat 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:hiddenandopacity:0are considered fully visible as far as Intersection Observer is concerned, leading to them not gettingfetchpriority=low. And notice how the element withcontent-visibility:autohas aboundingClientRectwith zeroed out values, leading it to not getloading=lazyby Image Prioritizer.In addition to the possibility of a new JS API, we should extend the element schema to include a
computedStyleobject. In fact, let's say instead ofgetComputedStyle()there was acaptureElementStyles()function passed toinitializeandfinalize. 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 thecomputedStyleobject of the element. Since thecomputedStyleobject 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.