Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new experimental fetchpriority module #528

Merged
merged 36 commits into from
Nov 23, 2022

Conversation

pbearne
Copy link
Contributor

@pbearne pbearne commented Sep 13, 2022

Summary

Fixes #477

Relevant technical choices

Checklist

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

@pbearne pbearne added this to the no milestone milestone Sep 13, 2022
pbearne and others added 3 commits September 13, 2022 11:58
Co-authored-by: Adam Silverstein <adamjs@google.com>
Co-authored-by: Adam Silverstein <adamjs@google.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pbearne This is a solid start. I left a few mostly small comments below, but there are two bigger things among them which are critical but missing here:

  1. We need to add support for the featured image output, as it is covered by the conditional lazy-loading logic as well.
  2. We should add at least one more test to cover the actual wp_filter_content_tags() integration of the code here.

modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
tests/modules/images/fetchpriority/Fetchpriority-Tests.php Outdated Show resolved Hide resolved
modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
tests/modules/images/fetchpriority/Fetchpriority-Tests.php Outdated Show resolved Hide resolved
@felixarntz felixarntz changed the title Experiment/fetchpriority Implement new experimental fetchpriority module Sep 13, 2022
pbearne and others added 4 commits September 13, 2022 15:29
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
@adamsilverstein
Copy link
Member

I verified this works as expected in a classic theme like twentytwelve.

when testing with twentytwentythree however, I noticed that the first image is lazy loaded, so something isn't quite working with the logic in core for block themes. I'm going to dig into this a bit further to see why. cc: @felixarntz

Copy link
Member

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adamsilverstein
Copy link
Member

when testing with twentytwentythree however, I noticed that the first image is lazy loaded, so something isn't quite working with the logic in core for block themes. I'm going to dig into this a bit further to see why.

As we had discussed earlier, this is caused by the block theme "double" pass at the content (which can help performance). To fix this we need to avoid "counting" the first pass by block themes. I noticed in this case the $context is false, so arrived at this simple solution which fixes the issue in my testing: WordPress/wordpress-develop#3538

I will open up a Trac ticket to discuss further.

@adamsilverstein
Copy link
Member

@pbearne this is ready for review.

@adamsilverstein
Copy link
Member

@felixarntz this is ready for review

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pbearne @adamsilverstein Overall this looks solid, though there are a few things we need to fix as they can introduce bugs.

In light of the currently ongoing work to fix image lazy-loading in block themes (see https://core.trac.wordpress.org/ticket/56930), we should make sure to test prior to merge that this works as expected in a block theme.

Looking at the code here, things look like this may not be affected by the double execution bug from core (due to the more explicit context check present here), but we need to verify that. Adding fetchpriority="high" to too many images may be even worse than lazy-loading too many images.

modules/images/fetchpriority/load.php Show resolved Hide resolved
modules/images/fetchpriority/load.php Show resolved Hide resolved
modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
@adamsilverstein
Copy link
Member

@felixarntz Addressed feedback and ready for another review

@adamsilverstein
Copy link
Member

we should make sure to test prior to merge that this works as expected in a block theme.

I will double check this.

@felixarntz felixarntz added this to the 1.8.0 milestone Nov 16, 2022
@felixarntz felixarntz removed the no milestone PRs that do not have a defined milestone for release label Nov 16, 2022
@felixarntz
Copy link
Member

Milestoning this for the 1.8.0 release coming in December, as it's shaping up for merge by then. I'll give it another review later this week.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pbearne @adamsilverstein The implementation here LGTM, with the following caveats / known issues:

Both of these problems are not critical, since at least this PR doesn't make it worse than it is; and both of these problems need to be fixed separately, so this is good to merge IMO.

Will update the module description though, as it's a bit too technical and doesn't describe the performance impact.

modules/images/fetchpriority/load.php Outdated Show resolved Hide resolved
@felixarntz
Copy link
Member

FYI the PR whatwg/html#8470 is where adding fetchpriority to the HTML spec is being worked on. This will be critical before we can eventually merge it into WordPress core. But for the plugin shipping this already should be fine.

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixarntz felixarntz merged commit 3cc0edc into trunk Nov 23, 2022
@felixarntz felixarntz deleted the experiment/fetchpriority branch November 23, 2022 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Feature A new feature within an existing module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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