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

#42438 wp_preload_links implementation #2505

Closed
wants to merge 13 commits into from

Conversation

manuelRod
Copy link

Trac ticket: https://core.trac.wordpress.org/ticket/42438


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.

@manuelRod manuelRod marked this pull request as draft April 4, 2022 13:42
Copy link
Member

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

Left a couple of comments. Overall looks quite nice.

But I would recommend also checking out WordPress/performance#31 before investing much more time into this.

One concern raised there was that providing this simply API doesn't provide particularly useful.

src/wp-includes/general-template.php Outdated Show resolved Hide resolved
src/wp-includes/general-template.php Show resolved Hide resolved
src/wp-includes/general-template.php Outdated Show resolved Hide resolved
src/wp-includes/general-template.php Outdated Show resolved Hide resolved
src/wp-includes/general-template.php Outdated Show resolved Hide resolved
@manuelRod
Copy link
Author

@swissspidy thanks for the feedback, I've addressed it. I also interacted on the performance issue, but I did not get any feedback from there.

@adamsilverstein
Copy link
Member

@manuelRod left some small feedback/questions on the PR

@manuelRod
Copy link
Author

@adamsilverstein thanks for the feedback, I left also some answers

*
* @since 6.0.0
*
* @param array $urls {
Copy link
Member

Choose a reason for hiding this comment

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

urls seems mis-named? maybe link_resources or link_attributes?

Copy link
Author

@manuelRod manuelRod May 11, 2022

Choose a reason for hiding this comment

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

@adamsilverstein I used $url the same way wp_resource_hints uses it. Since both share a similar structure/naming, I didn't want to introduce many changes.

Copy link
Member

Choose a reason for hiding this comment

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

👍🏼 I see, poor naming choice but ok!

Copy link
Contributor

@azaozz azaozz Jul 7, 2022

Choose a reason for hiding this comment

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

I used $url the same way wp_resource_hints uses it.

I see. However imho in both places the name is no good, unfortunately. On top of that further down the var $url is reset/reused. Not sure that's a good choice, perhaps better to have different names?

IMHO, best to make the names here descriptive, self-documenting and also fix the confusing naming in wp_resource_hints. Thinking both of @adamsilverstein's suggestions are better, maybe link_attributes makes a bit more sense.

Copy link
Member

Choose a reason for hiding this comment

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

since we are renaming the function slightly based on your last comment to wp_preload_resources, thinking the variable name would be $preload_resources. How does that sound?

@manuelRod manuelRod marked this pull request as ready for review May 11, 2022 14:01
@manuelRod manuelRod changed the title INITS-20 wp_preload_links implementation #42438 wp_preload_links implementation May 12, 2022
@manuelRod
Copy link
Author

@adamsilverstein @swissspidy @spacedmonkey all ready here

@spacedmonkey
Copy link
Member

Please update on references to 6.0.0 and change them to 6.1.0.

@spacedmonkey
Copy link
Member

This feels like it is very close.

little refactor (printf instead of echo)
@manuelRod
Copy link
Author

@spacedmonkey references version bumped

@spacedmonkey spacedmonkey requested a review from felixarntz May 17, 2022 12:18

$atts = $url;
if ( isset( $url['href'] ) ) {
$url = $url['href'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think resetting/reusing vars is a good idea, ever. I know, it comes from wp_resource_hints() however it should be fixed there rather than replicated here. See above.

Copy link
Member

Choose a reason for hiding this comment

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

fixed here

}
$unique_urls[ $url ] = $atts;
// Media can use imagesrcset and not href.
} elseif ( ! isset( $url['href'] )
Copy link
Contributor

Choose a reason for hiding this comment

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

The first condition seems redundant? We already know it is an array, so if an element is isset() what's the point in doing elseif ( ! isset() )?

Copy link
Member

Choose a reason for hiding this comment

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

removed redundant ! isset()

continue;
}

$atts = $url;
Copy link
Contributor

Choose a reason for hiding this comment

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

$atts means attributes, right? Why not use the whole word. Makes it a tiny bit easier to read :)

Copy link
Member

Choose a reason for hiding this comment

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

renamed

continue;
}

foreach ( $unique_urls as $unique_atts ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Uh, what's $unique_atts? :)

Copy link
Member

Choose a reason for hiding this comment

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

changed this to foreach ( $unique_resources as $unique_resource ) {

Comment on lines +3502 to +3505
|| (
! in_array( $attr, array( 'as', 'crossorigin', 'href', 'imagesrcset', 'imagesizes', 'type', 'media' ), true )
&& ! is_numeric( $attr )
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this can be split into several conditionals to make it easier to read? Seems it will be a lot better/simpler.

* @dataProvider provider_preload_links
*/
public function test_preload_links( $expected, $urls ) {
$callback = function () use ( $urls ) {
Copy link
Contributor

@azaozz azaozz Jul 7, 2022

Choose a reason for hiding this comment

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

As above, seems $urls is not a good descriptive name for this. It doesn't contain just URLs, right? link_attributes would probably be better.

Copy link
Member

Choose a reason for hiding this comment

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

renamed preload_resources

@adamsilverstein
Copy link
Member

@manuelRod 👋🏼 I'm going to pick this up and add the recommended feedback above to help move this ticket forward.

}

$unique_urls = array();
foreach ( $urls as $url ) {
Copy link
Member

Choose a reason for hiding this comment

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

changed to foreach ( $preload_resources as $resource )

@adamsilverstein
Copy link
Member

@manuelRod - I was unable to push changes here, I don't have permissions. So instead I opened a new PR on my fork - #3041; happy to close that and push changes here instead if you can give me that capability, otherwise will continue work there. If you review the last commit(s) you will see the fixes from the feedback above.

@adamsilverstein
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants