[wp-trac] [WordPress Trac] #42438: preload is missing from ressource hints.
WordPress Trac
noreply at wordpress.org
Tue Jul 31 18:16:00 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):
Replying to [comment:6 igrigorik]:
> Not sure if "bad" is the right term, but at a risk of being pedantic..
personally I _would_ prefer if preload was exposed as standalone and
separate API: "hints" have a different semantic and UA behavior from
preload and merging them into the same API might cause unnecessary
confusion for a bunch of folks.
>
> If I could make a wish, I think it would be:
>
> - deprecate `as` and `pr` attributes on `wp_resource_hints`
> - introduce `wp_preload` with support for `as` *and* enforce that `as`
must be provided
>
> Splitting these into separate top level APIs matches the spec behavior
and intent, and I think it would help developers navigate the requirements
much more clearly too.
That sounds good. I think `wp_preload_links` would be marginally better
name for this function/filter. A benefit to having a separate function as
you proposed is that it simplifies the filter. Instead of
[https://core.trac.wordpress.org/ticket/42438?replyto=6#comment:5 as
above] having to check `'preload' === $relation_type` the filter could be
instead added simply as:
{{{#!php
<?php
add_filter( 'wp_preload_links', function( $urls ) {
$urls[] = array(
'as' => 'script',
'href' => 'https://cdn.ampproject.org/v0.js',
);
return $urls;
} );
}}}
Aside: I've opened a [https://github.com/Automattic/amp-wp/pull/1295 PR]
to add the requisite `preload` links for the AMP plugin via the post-
processor. This works in the AMP plugin because we have the output loaded
in a `DOMDocument` for manipulation which isn't an approach available in
WordPress normally.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42438#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list