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
Update DetermineHeroImages transformer to use loading=lazy as a signal for images which should not be prerendered. As can be seen in wpcore#52139, the featured image omits the loading attribute for the featured image because it should not be loaded lazily. This is in contrast with images which are added to the content, which should be (normally). Another example of this is the Custom Logo which likewise does not get loading=lazy as per wpcore#50425.
The DetermineHeroImages transformer currently does SSR for Image blocks and Cover blocks which are at the beginning of the content:
What could change however is the logic for determine the custom header and custom logo which currently rely on specific class names being present (and where there is a lack of standardization for custom headers):
This will select the first image that was not originally marked with loading=lazy (as the AMP_Img_Sanitizer will preserve that in the noscript fallback).
For fear of CUSTOM_HEADER_XPATH_QUERY accidentally selecting an image out of the first viewport, some protection for this is proposed in ampproject/amp-toolbox#1196. However, we'll have to decide whether data-hero-candidate should also get loading=lazy added to the SSR'ed image. Also, while using loop_start as suggested in #5934 (review) wasn't ideal, something else we could consider for the header image is only image elements that occur before main or else FIRST_ENTRY_CONTENT_XPATH_QUERY.
Aside: The CUSTOM_LOGO_XPATH_QUERY should also be modified to only select the first result by adding [1] to the end of the expression. (That doesn't work as it just selects the first child, not the first instance overall.)
With these changes, we can then the DetermineHeroImages transformer by default, whereas currently we only enable it for the core themes.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered:
Feature description
Update
DetermineHeroImages
transformer to useloading=lazy
as a signal for images which should not be prerendered. As can be seen in wpcore#52139, the featured image omits theloading
attribute for the featured image because it should not be loaded lazily. This is in contrast with images which are added to the content, which should be (normally). Another example of this is the Custom Logo which likewise does not getloading=lazy
as per wpcore#50425.The
DetermineHeroImages
transformer currently does SSR for Image blocks and Cover blocks which are at the beginning of the content:amp-wp/src/Transformer/DetermineHeroImages.php
Lines 56 to 75 in 81b9df7
That can remain in place.
What could change however is the logic for determine the custom header and custom logo which currently rely on specific class names being present (and where there is a lack of standardization for custom headers):
amp-wp/src/Transformer/DetermineHeroImages.php
Lines 35 to 40 in 81b9df7
The
CUSTOM_HEADER_XPATH_QUERY
in particular could be replaced as follows:This will select the first image that was not originally marked with
loading=lazy
(as theAMP_Img_Sanitizer
will preserve that in thenoscript
fallback).For fear of
CUSTOM_HEADER_XPATH_QUERY
accidentally selecting an image out of the first viewport, some protection for this is proposed in ampproject/amp-toolbox#1196. However, we'll have to decide whetherdata-hero-candidate
should also getloading=lazy
added to the SSR'ed image. Also, while usingloop_start
as suggested in #5934 (review) wasn't ideal, something else we could consider for the header image is only image elements that occur beforemain
or elseFIRST_ENTRY_CONTENT_XPATH_QUERY
.Aside: The(That doesn't work as it just selects the first child, not the first instance overall.)CUSTOM_LOGO_XPATH_QUERY
should also be modified to only select the first result by adding[1]
to the end of the expression.With these changes, we can then the
DetermineHeroImages
transformer by default, whereas currently we only enable it for the core themes.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered: