#38121 closed enhancement (fixed)
Crossorigin and other attributes for wp_resource_hints
Reported by: | superpoincare | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | Script Loader | Keywords: | has-patch has-unit-tests commit has-dev-note |
Focuses: | performance | Cc: |
Description
At present, wp_resource_hints doesn't allow various attributes that can be added to the link element. One example is preconnect.
This is required for preconnect to Google fonts to work.
See this example: https://www.webpagetest.org/video/compare.php?tests=160921_P0_2GSV,160921_QP_2GSW
Related ticket: https://core.trac.wordpress.org/ticket/37171
Hence I am opening this ticket: for enhancement to wp_resource_hints
Attachments (5)
Change History (24)
#2
follow-up:
↓ 3
@
5 years ago
Attributes have come up before, but we didn't really have time to consider all of them, especially since the specification is still in draft status.
There's the hint probability (pr
) attribute (https://www.w3.org/TR/resource-hints/#attributes) as well as the as
attribute. crossorigin
can also have a value, e.g. crossorigin="use-credentials"
, see https://html.spec.whatwg.org/multipage/infrastructure.html#cors-settings-attributes.
Also, we might want to support preload
as well.
Of course, this all would need to be done in a backward compatible way.
#3
in reply to:
↑ 2
@
5 years ago
Replying to swissspidy:
Of course, this all would need to be done in a backward compatible way.
A couple of possibilities, each attribute can be a string (URL only) or one of the following:
'example.com' => array( 'cross-origin' => 'user-credentials', 'other' => 'atts' ),
or
array( 'href' => 'example.com', //alias with url 'cross-origin' => 'user-credentials', 'other' => 'atts' ),
an is_array
check is used to determine if the additional attributes exist.
This ticket was mentioned in Slack in #core by swissspidy. View the logs.
5 years ago
#5
@
5 years ago
- Milestone changed from Awaiting Review to 4.7
- Owner set to swissspidy
- Status changed from new to assigned
#7
@
5 years ago
@peterwilsoncc @voldemortensen What do you folks think of the latest patch + tests?
#8
@
5 years ago
The once change I'd make to your patch is to replace a number if else if
s with elseif
, see 38121.2.diff.
Seeing it code, I'm not sure my first suggestion above is a good idea afterall. It seems a bit error prone. I'll work on something seperate.
#9
@
5 years ago
38121.3.diff uses the second format from comment:3. No url alias for href as it's not done elsewhere.
#11
@
5 years ago
38121.4.diff fixes a couple of bugs from the previous patches. Also makes sure that invalid entries with no href
attribute are skipped.
#12
@
5 years ago
- Keywords commit added
LGTM, minor styling issue in attribute loop with ... && ! is_numeric( $attr ))
but apart from that looks ready for commit.
#13
@
5 years ago
Shouldn't preload
be handled in a separate ticket? See also https://github.com/w3c/preload/issues/76 for current browser support.
#14
@
5 years ago
@ocean90 I'd usually agree, but these two specs are kinda tied together. See the as
attribute as an example:
The
as
attribute is an optional attribute that must conform to requirements defined in PRELOAD.
This ticket was mentioned in Slack in #core by desrosj. View the logs.
5 years ago
#16
@
5 years ago
Actually, ignore my previous comment. preload
is really not the original goal of this ticket. It deserves its own ticket + discussion.
See 38121.5.diff.
This ticket was mentioned in Slack in #core-themes by davidakennedy. View the logs.
5 years ago
#19
@
15 months ago
- Keywords has-dev-note added; needs-dev-note removed
Linking the dev note that was published here for reference: https://make.wordpress.org/core/2016/11/03/attributes-for-resource-hints-in-4-7/
Any thoughts on this @swissspidy & @voldemortensen?
I'm inclined to be opinionated and include the crossorigin attribute where needed given the aim is to reduce lag cross origin.