[wp-trac] [WordPress Trac] #52465: Allow a relation type in resource hints to be used multiple times
WordPress Trac
noreply at wordpress.org
Fri Apr 30 21:30:41 UTC 2021
#52465: Allow a relation type in resource hints to be used multiple times
-----------------------------------------------------+---------------------
Reporter: GeekPress | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 5.8
Component: Script Loader | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests needs-dev-note | Focuses:
-----------------------------------------------------+---------------------
Changes (by audrasjb):
* keywords: has-patch has-unit-tests => has-patch has-unit-tests needs-
dev-note
* milestone: Awaiting Review => 5.8
Comment:
Hello, thanks both for the patchs/unit tests,
I tested the pull request using the test code provided by @GeekPress:
{{{
function preconnect_mycdn( $hints, $relation_type ) {
$domains = [
[
'href' => '//mycdn.test/',
],
[
'href' => '//mycdn.test/',
'crossorigin' => 'use-credentials',
],
[
'href' => '//mycdn.test/',
],
[
'href' => '//mycdn.test/',
'crossorigin' => 'anonymous',
],
];
foreach ( $domains as $domain ) {
if ( 'preconnect' === $relation_type ) {
$hints[] = $domain;
}
}
return $hints;
}
add_filter( 'wp_resource_hints', 'preconnect_mycdn', 10, 2 );
}}}
Before PR 1216 is applied, this result to this single line being printed
in the `head` section of the page:
{{{
<link href='//mycdn.test' crossorigin='anonymous' rel='preconnect' />
}}}
After applying the PR, here's the result:
{{{
<link href='//mycdn.test' rel='preconnect' />
<link href='//mycdn.test' crossorigin='anonymous' rel='preconnect' />
}}}
The PR seems to work as expected. Plus, it has unit tests. Therefore, I'm
moving this for 5.8 consideration.
Also adding `needs-dev-note` keyword, in case the change can make it into
5.8.
Thanks all
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52465#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list