[wp-trac] [WordPress Trac] #42438: preload is missing from ressource hints.
WordPress Trac
noreply at wordpress.org
Mon Jul 30 02:31:22 UTC 2018
#42438: preload is missing from ressource hints.
------------------------------------------+-------------------------
Reporter: nico23 | Owner: swissspidy
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 5.0
Component: Script Loader | Version: 4.9
Severity: normal | Resolution:
Keywords: needs-unit-tests needs-patch | Focuses:
------------------------------------------+-------------------------
Comment (by westonruter):
I just ran across this as I was looking to add `<link rel="preload"
as="script" href="https://cdn.ampproject.org/v0.js">` to the AMP plugin.
While preload != resource hints it seems the existing resource hints API
in WordPress is well suited for preload. For example, with
[attachment:"add_preload_to_ressource_hints.patch"]:
{{{#!php
<?php
add_filter( 'wp_resource_hints', function( $urls, $relation_type ) {
if ( 'preload' === $relation_type ) {
$urls[] = array(
'rel' => 'preload',
'as' => 'script',
'href' => 'https://cdn.ampproject.org/v0.js',
);
}
return $urls;
}, 10, 2 );
}}}
@igrigorik Would this be bad?
As for the `pr` attribute in `wp_resource_hints()`, it's just allowing for
the attribute to be used, it doesn't mandate it. We could add a special
condition to `_doing_it_wrong()` if that attribute is provided. Likewise,
we could call `_doing_it_wrong()` if the `as` attribute is used with
anything other than `rel=preload`.
Also, does it matter the order of the links? Should `preload` links come
after resource hint links?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42438#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list