Skip to content

Fetchpriority - add a fetchpriority=high attribute to the non-lazy image(s) #477

Closed

Description

@adamsilverstein

Overview

  • Proposed module name: Fetchpriority
  • Proposed module slug: fetchpriority
  • Proposed module owner GitHub username(s): pbearne, adamsilverstein

About the module

Adding the fetchpriority attribute high attribute to the LCP (or first large) image on the page should improve the page's LCP, because it tells the browser to prioritize loading that image.

We can build this as a module (possibly experimental), then measure its impact on performance. Note: as of this writing, fetchpriority is only supported in chrome and edge.

Purpose

Scope

WordPress already determines which image is most likely to be the "LCP" image in wp_get_loading_attr_default, excluding the loading=lazy attribute. We can leverage this to add fetchpriority=high to those same images, which should cause the browser to prioritize their load.

Rationale

fetchpriority is a new approach to priority hinting that improves on features like preload. Adding this module will let the performance team test this feature as a potential improvement for core.

Other

Read this document for the details: https://web.dev/priority-hints/#the-fetchpriority-attribute

Activity

  1. mxbclang commented on Aug 17, 2022

    @mxbclang
    Contributor

    To be discussed in August 23 performance chat.

  2. gilbertococchi commented on Aug 22, 2022

    @gilbertococchi

    +1 about this experimentation.

    I believe this would be a game changer for most of the WP sites using Render Blocking resources where the main page content is an image.

    Below a small image showing the effect of fetchpriority=high added to a Featured image on a WP site, Image starts to be downloaded way earlier, increasing the chance to deliver the image quickly to sites also on Budget hosting.

    fetchpriority_high

  3. eugene-manuilov commented on Aug 23, 2022

    @eugene-manuilov
    Contributor

    WordPress already determines which image is most likely to be the "LCP" image in wp_get_loading_attr_default, excluding the loading=lazy attribute. We can leverage this to add fetchpriority=high to those same images, which should cause the browser to prioritize their load.

    Just want to say that we need to make sure we add the fetchpriority=high attribute based on presence of the loading=lazy attribute in an image. We can't use the wp_get_loading_attr_default function to determine wether an image has lazyloading or not.

  4. mehigh commented on Aug 23, 2022

    @mehigh

    Here’s where I read about this, and then tried it out
    https://web.dev/priority-hints/#using-preload-after-chrome-95:~:text=Priority%20hints%20can%20complement,with%20fetchpriority%20%3D%20%22high%22.
    In short -> if an image preload is added, it’s added to the queue early, but with a low priority -> and that’s because of the type of resource it is (an image).
    If the preload tag receives this extra attribute fetchpriority="high" - as it should be used on a LCP image, that switches the priority levels (not on every browser) and maintains a high priority in the network queue (and wouldn’t be pushed for later by render blocking resources for example).
    This is a nice to have, but rather granular, advanced type of optimization when there’s a high certainty that the image is the LCP for the particular page.
    Since preload is a mandatory fetch and not a hint, using it wrong can negatively impact performance (like slowing down things when preloading with a fetchpriority of high a ton of resources).
    Outside of this exact specific context -> the LCP image using a responsive preload + fetchpriority high, I didn’t encounter a scenario that mandated using it in production for a performance gain.
    A preload for a style tag or script tag automatically received a high priority, so setting the fetchpriority of high made no difference.
    So as with everything web performance 🙂 it depends.
    But yes, it’s a clear use-case where this attribute can benefit.
    I didn’t see it yield such a big difference in my tests when placed on an image tag though, while the preload made a bigger impact.
    Grain of salt addition - my experiment was limited to sites with large HTMLs (300KB+) - so not specifically 'smack' in the middle of an average WP site, and the conclusion drawn was going towards the preload approach as the go-to strategy.

  5. tunetheweb commented on Aug 23, 2022

    @tunetheweb
    Contributor

    FYI, more guidance on it here: https://web.dev/optimize-lcp/#optimize-the-priority-the-resource-is-given.

    In short, adding it to the LCP <img> tag should allow Chromium-based browsers to start fetching it early (as shown in the waterfall example in #477 (comment)). It can also be added to preload links for images that are not immediately discoverable from the raw HTML.

    You are correct it's not needed for script or CSS tags in the head (with or without preload) since they are already high priority, so one of the main benefits is for LCP images which are low-priority until the initial layout and render as they have, in the past, been considered less important as not render-blocking. LCP has bumped the importance of this for LCP images from that past thinking.

    It's also possible to lower the priority of less-important resources (e.g. some scripts), but will leave that aside as that's not what is being proposed here.

    And yes, should avoid overusing this: If you prioritise everything, then you're basically prioritising nothing!

  6. gilbertococchi commented on Aug 24, 2022

    @gilbertococchi

    Hi Mike, as Barry correctly said, the fetchpriority=high attribute could be simply added on the IMG tag without need to add a Link Preload in the Head.

    That's the first real benefit in my opinion, because if a Wordpress Website may have a Render Blocking JS in the Head (like jQuery that is pretty common in my experience) by simply adding fetchpriority=high to the post larger IMG tag the Image Network Request would start earlier at a similar time of the Render Blocking JS Network Request in the Head (see my screenshot on comment #issuecomment-1221997449).

  7. mehigh commented on Aug 24, 2022

    @mehigh

    Agree, the adding on the img tag is a positive. What I'm hoping is that it won't over-extend: for a bunch of images to not intentionally receive fetchpriority=high when they're not lazy loaded, but rather for the specific first / featured image or whatever logic we want to add here.

  8. pbearne commented on Aug 24, 2022

    @pbearne
    Contributor

    If no one what to code this I will do it

    its just a few lines of code with new filter wp_content_img_tag

  9. gilbertococchi commented on Aug 25, 2022

    @gilbertococchi

    @mehigh I agree with your concerns, it should be ideal that only one image to have fetchpriority=high.
    While it's true that this feature is way less dangerous than a misuse of Link Preload IMGs in the Head, it should be controlled somehow, that's why the experiment phase is so important.

    I can see that in case of Blog Listing pages (depending by the layout) it may be interesting to have more but it should be up to the theme developer to implement this in my opinion.

    Achieving the result to apply the attribute to the first Post Image Thumbnail should be sufficient to increase the chance to deliver the image in a good amount of time.

    Gil

  10. gilbertococchi commented on Aug 29, 2022

    @gilbertococchi

    @pbearne Thanks for your feedback, it would be great!

    It's a great idea to use the wp_content_img_tag filter to detect that and experiment this out.

    @adamsilverstein, WDYT?

  11. mxbclang commented on Sep 12, 2022

    @mxbclang
    Contributor

    Thank you, @pbearne! Assigning this to you for now and moving to To Do.

    @adamsilverstein Please see @gilbertococchi's comment above when you get a moment.

  12. felixarntz commented on Sep 13, 2022

    @felixarntz
    Member

    @pbearne I've added you as a module owner here as discussed earlier today, also pushed the corresponding CODEOWNERS change to your PR in 280f11d.

  13. changed the title [-]Module Proposal: Fetchpriority - add a `fetchpriority=high` attribute to the non-lazy image(s)[/-] [+]Fetchpriority - add a `fetchpriority=high` attribute to the non-lazy image(s)[/+] on Sep 14, 2022
  14. mxbclang commented on Sep 14, 2022

    @mxbclang
    Contributor

    @pbearne @felixarntz Heads up that I've updated this issue and #528 to remove the module proposal labels/title (since we're now using this for the module implementation itself) and I've created and added a new label for this new module.

  15. felixarntz commented on Sep 14, 2022

    @felixarntz
    Member

    @bethanylang Fair point. I was thinking that we can also use the module proposal to code the first piece of the module against it once it's approved, but probably cleaner indeed to have a more targeted issue. Maybe for next time I'd suggest we then open an entirely new one so that we keep the module proposal as is for history.

  16. mxbclang commented on Sep 14, 2022

    @mxbclang
    Contributor

    @felixarntz Yep, that's what we usually do, but y'all got started without me! Will do for next time.

  17. felixarntz commented on Sep 14, 2022

    @felixarntz
    Member

    @bethanylang Sorry! 🤣

  18. adamsilverstein commented on Nov 17, 2022

    @adamsilverstein
    MemberAuthor

    We can build this as a module (possibly experimental), then measure its impact on performance. Note: as of this writing, fetchpriority is only supported in chrome and edge.

    Note that based on this comment Gecko (Mozilla) plans to implement this in Q1 of 2023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Type] FeatureA new feature within an existing module

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions