Ensure IMG with fetchpriority=low does not get lazy-loaded, increase media count, or interfere with assigning fetchpriority=high#11196
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Pull request overview
Updates core loading-optimization heuristics to treat img[fetchpriority=low] as a special case so it won’t be lazy-loaded, won’t affect the content media count, and won’t interfere with assigning fetchpriority=high to the first in-viewport large image.
Changes:
- Extend
wp_get_loading_optimization_attributes()to recognize existingfetchpriority=lowand avoid addingloading="lazy"/ incrementing media count. - Add PHPUnit coverage to ensure
fetchpriority=lowimages don’t influence the “first N images not lazy-loaded” and high-priority selection logic.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/wp-includes/media.php |
Adds fetchpriority=low handling in loading optimization logic and documents the behavior. |
tests/phpunit/tests/media.php |
Adds helper + additional assertions to cover fetchpriority=low interactions across contexts/loops. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Trac ticket: https://core.trac.wordpress.org/ticket/64823
With WordPress/gutenberg#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:
Before ❌
[ { "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" } ]After ✅
[ { "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" } ]The diff shows the changes to the first three images in the content (outside of the navigation overlay):
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
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.