-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add preload links LCP picture elements #1707
Merged
westonruter
merged 31 commits into
WordPress:trunk
from
b1ink0:fix/preload-lcp-images-for-picture-elements
Dec 5, 2024
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
43525c0
Fix preloading of LCP images for <picture> elements
b1ink0 c20943c
Add media attribute support for <source> elements in image prioritiza…
b1ink0 83c19a2
Break logic into multiple methods for handling img and picture tag pr…
b1ink0 2b812fb
Remove handling of picture with no source scenario
b1ink0 df1d90e
Ensure source elements have a type attribute and no media attribute, …
b1ink0 b8a17c0
Refactor conditional logic so the cases are consistent
b1ink0 194075c
Refactor get_parent_tag_name to use breadcrumbs from context and rena…
b1ink0 ff8df96
Move pre_img_process logic directly into process_img method
b1ink0 bc178ba
Refactor to use single function for adding preload links
b1ink0 ed2e2da
Merge branch 'trunk' into fix/preload-lcp-images-for-picture-elements
b1ink0 664c228
Refactor how preload links are added
westonruter d76759e
Align phpdoc in get_breadcrumbs() with WP_HTML_Processor
westonruter a767385
Add test for type attribute on link
westonruter 34272cd
Fix sourcing of crossorigin and referrerpolicy attributes
westonruter b468896
Only capture the first source
westonruter 93a0f1b
Use upper-case tag names rather than markup in phpdoc
westonruter bf3932f
Add test for get_breadcrumbs() and fix bug in implicit P closing
westonruter 71c198c
Merge branch 'trunk' into fix/preload-lcp-images-for-picture-elements
b1ink0 79d5fc3
Add test case for picture element with LCP image and fully populated …
b1ink0 9f593a2
Add test case for picture element with missing LCP metrics for tablet…
b1ink0 f3c2b6b
Add test case for picture element with missing type attribute in source
b1ink0 ac9f499
Add tests for picture element with media attribute in source
b1ink0 71adb58
Add test case for picture element with crossorigin and referrerpolicy…
b1ink0 d7d24b4
Merge branch 'trunk' into fix/preload-lcp-images-for-picture-elements
b1ink0 b4660de
Improve normalization of crossorigin attribute value
westonruter e7cb4a7
Harden processing of PICTURE tag
westonruter ebbf0d3
Supply missing array key
westonruter 7d2e654
Factor out common logic to obtain valid src attribute
westonruter a92b899
Update test case to test for multiple sources
westonruter 8f6550a
Remove largely duplicate test case by merging
westonruter ece0618
Reuse get_valid_src to obtain valid srcset
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of relying on this
__invoke
function being called on thePICTURE
and then also on the childSOURCE
tags (andIMG
) tag, I suggest instead that when'PICTURE' === $tag
that this here call a new method likeprocess_picture()
and that this method would:$processor->set_bookmark( 'img-prioritizer-picture' )
while( $processor->next_tag()
loop. Note that our subclass'snext_tag()
method always visits tag closers until$processor->get_tag() === 'picture' && $processor->is_tag_closer()
.SOURCE
tags and the finalIMG
tag.$processor->set_bookmark('img-prioritizer-picture')
.$context->link_collection->add_link()
, leaving the other location as-is for just for processing bareIMG
tags.This approach of a sub-loop was also taken by Embed Optimizer in
embed_optimizer_update_markup()
.