#52139 closed defect (bug) (fixed)
Twenty Twenty-One: Skip loading attribute on featured image instead of loading=eager
Reported by: | flixos90 | Owned by: | desrosj |
---|---|---|---|
Milestone: | 5.6.1 | Priority: | normal |
Severity: | normal | Version: | 5.6 |
Component: | Bundled Theme | Keywords: | has-patch, fixed-major, twenty-twenty-one-1.1 |
Focuses: | Cc: |
Description
The new default theme is providing a loading="eager"
for featured images displayed, however this is a discouraged pattern per this section:
For example, if an image is placed within the
header.php
template and is very likely to be in the initial viewport, it is advisable to skip theloading
attribute for that image.
To clarify, "skip" means omit the loading
attribute, not set it to "eager". The reason is that specifying "eager" explicitly requires the browser to load the image right away rather than leaving control to the browser, which means that even in special modes like e.g. Chrome Lite mode for slow network connections these images would be forced to load right away, causing a potentially worse experience.
We therefore should remove the loading
attribute for featured images instead of specifying it as "eager".
Change History (13)
This ticket was mentioned in PR #831 on WordPress/wordpress-develop by felixarntz.
4 years ago
#1
- Keywords has-patch added
This ticket was mentioned in Slack in #core-themes by desrosj. View the logs.
4 years ago
#3
@
4 years ago
- Milestone changed from 5.7 to 5.6.1
Thanks @flixos90! This looks good to me. I think we can consider including this in the 1.1 version being released today as well. Moving to 5.6.1 and I'll hold off to allow more time for another theme focused contributor to review.
#4
@
4 years ago
If I remember correctly this was added to prevent layout shifting. I don't know enough to determine what should be prioritized here.
I would rather wait to 5.7 or 5.6.1 so that all opinions can be heard, in the ticket.
#5
@
4 years ago
Lazy-loading an image in the initial viewport can have a negative impact on the Largest Contentful Paint Metric (also see https://web.dev/browser-level-lazy-loading-for-cmss/#avoid-lazy-loading-above-the-fold-elements).
The change made in this ticket doesn't affect that though: The image not being lazy-loaded is maintained, it's only about the implementation, where passing loading="eager"
is discouraged for the reason outlined in the description.
#6
@
4 years ago
The reasoning for not adding loading="eager"
described here makes sense to me.
While using
loading="eager"
is a supported alternative, this would tell the browser explicitly to always load the image right away, which would prevent potential benefits if browsers implemented further mechanisms and heuristics to automatically decide which elements to lazy-load.
While eager
is the default value for loading
, explicitly setting it communicates something to the browser that might block future performance benefits.
Setting loading
to false
removes the lazy-loading from the image, which should prevent any layout shift.
This ticket was mentioned in Slack in #core-themes by desrosj. View the logs.
4 years ago
#10
@
4 years ago
- Keywords fixed-major added; commit removed
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening to backport.
4 years ago
#11
Merged into core in https://core.trac.wordpress.org/changeset/49860.
Trac ticket: https://core.trac.wordpress.org/ticket/52139