Opened 3 weeks ago
Closed 3 weeks ago
#64823 closed defect (bug) (fixed)
Image in navigation overlay or in viewport-conditional block can get `fetchpriority=high` and degrade LCP metric for page
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | Media | Keywords: | has-patch has-unit-tests |
| Focuses: | performance | Cc: |
Description (last modified by )
This ticket is a companion to the corresponding Gutenberg#76181 and Gutenberg#76301 issues.
When an IMG is added to the new Navigation Overlay in WP 7.0, it can get misidentified as deserving fetchpriority=high when the actual LCP element IMG is further down it the page.
While the Gutenberg PR addresses this issue by adding fetchpriority=low to such IMG tags, the logic in wp_get_loading_optimization_attributes() needs to be updated to account for such tags so that they do not get lazy-loaded. WHen an image is in the Navigation Overlay or somewhere else that is occluded from view (e.g. a Details block or non-initial carousel slide), it is very important for the IMG to not get lazy-loaded because it means there will be a delay when attempting to view the image since it isn't loaded yet. For the Navigation Overlay, there is no browser heuristic to know it should start to load the image prior to the user clicking on the nav menu button. So the images must be loaded unconditionally, but in a deprioritized way that does not compete with loading resources in the critical rendering path.
For more, see docs on web.dev: https://web.dev/articles/fetch-priority#lower-carousel-priority
Similarly, when a block is displayed conditionally in a viewport with block visibility, it may erroneously get fetchpriority=high even though it is not displayed. This is due to logic in wp_get_loading_optimization_attributes() and wp_maybe_add_fetchpriority_high_attr() and it can be avoided by adding fetchpriority=auto to IMG tags in such blocks. See Gutenberg issue. A further needed improvement is to avoid IMG tags with fetchpriority=auto from contributing to the overall media count so that that don't cause lazy-loading to be added prematurely.
Change History (5)
This ticket was mentioned in PR #11196 on WordPress/wordpress-develop by @westonruter.
3 weeks ago
#1
- Keywords has-patch has-unit-tests added
@westonruter commented on PR #11196:
3 weeks ago
#2
cc @mukeshpanchal27
#3
@
3 weeks ago
- Description modified (diff)
- Summary changed from Image in navigation overlay can get `fetchpriority=high` and degrade LCP metric for page to Image in navigation overlay or in viewport-conditional block can get `fetchpriority=high` and degrade LCP metric for page
@westonruter commented on PR #11196:
3 weeks ago
#4
@mukeshpanchal27 I've expanded the scope here to include the _closely_ related changes for block visibility described in https://github.com/WordPress/gutenberg/issues/76301.
Trac ticket: https://core.trac.wordpress.org/ticket/64823
With https://github.com/WordPress/gutenberg/pull/76208 checked out and there are 5 large images added to a Navigation Overlay and 5 large images in the post content, given the following script being run in the console:
<details><summary>Before ❌</summary>
[ { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": false, "loading": "lazy", "fetchPriority": "auto" }, { "insideNavOverlay": false, "loading": "lazy", "fetchPriority": "auto" }, { "insideNavOverlay": false, "loading": "lazy", "fetchPriority": "auto" }, { "insideNavOverlay": false, "loading": "lazy", "fetchPriority": "auto" }, { "insideNavOverlay": false, "loading": "lazy", "fetchPriority": "auto" } ]</details>
<details><summary>After ✅</summary>
[ { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": true, "loading": "auto", "fetchPriority": "low" }, { "insideNavOverlay": false, "loading": "auto", "fetchPriority": "high" }, { "insideNavOverlay": false, "loading": "auto", "fetchPriority": "auto" }, { "insideNavOverlay": false, "loading": "auto", "fetchPriority": "auto" }, { "insideNavOverlay": false, "loading": "lazy", "fetchPriority": "auto" }, { "insideNavOverlay": false, "loading": "lazy", "fetchPriority": "auto" } ]</details>
The diff shows the changes to the first three images in the content (outside of the navigation overlay):
.json
lazy",auto"lazy",lazy",Fixes:
fetchpriority=highbeing assigned to the first large image outside of the Navigation Overlay.loading=lazyon the first three images in the content.## Use of AI Tools
None