Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 4 years ago

#38121 closed enhancement (fixed)

Crossorigin and other attributes for wp_resource_hints

Reported by: superpoincare's profile superpoincare Owned by: swissspidy's profile 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:


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:,160921_QP_2GSW

Related ticket:

Hence I am opening this ticket: for enhancement to wp_resource_hints

Attachments (5)

38121.diff (5.6 KB) - added by swissspidy 8 years ago.
38121.2.diff (5.6 KB) - added by peterwilsoncc 8 years ago.
38121.3.diff (5.6 KB) - added by peterwilsoncc 8 years ago.
38121.4.diff (5.7 KB) - added by swissspidy 8 years ago.
38121.5.diff (4.3 KB) - added by swissspidy 8 years ago.

Download all attachments as: .zip

Change History (24)

#1 @peterwilsoncc
8 years ago

  • Version changed from 4.6.1 to 4.6

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.

#2 follow-up: @swissspidy
8 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 ( as well as the as attribute. crossorigin can also have a value, e.g. crossorigin="use-credentials", see

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 @peterwilsoncc
8 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:

'' => array( 
  'cross-origin' => 'user-credentials', 
  'other' => 'atts'


  'href' => '',  //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.

8 years ago

#5 @swissspidy
8 years ago

  • Milestone changed from Awaiting Review to 4.7
  • Owner set to swissspidy
  • Status changed from new to assigned

8 years ago

#6 @swissspidy
8 years ago

  • Keywords has-patch has-unit-tests added

#7 @swissspidy
8 years ago

@peterwilsoncc @voldemortensen What do you folks think of the latest patch + tests?

#8 @peterwilsoncc
8 years ago

The once change I'd make to your patch is to replace a number if else ifs 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 @peterwilsoncc
8 years ago

38121.3.diff uses the second format from comment:3. No url alias for href as it's not done elsewhere.

#10 @swissspidy
8 years ago

  • Keywords needs-dev-note added

8 years ago

#11 @swissspidy
8 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 @peterwilsoncc
8 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 @ocean90
8 years ago

Shouldn't preload be handled in a separate ticket? See also for current browser support.

#14 @swissspidy
8 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.

8 years ago

8 years ago

#16 @swissspidy
8 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.

Last edited 6 years ago by swissspidy (previous) (diff)

#17 @swissspidy
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 38826:

Resource Hints: Allow passing custom attributes to resource hints.

[37920] introduced resource hints that allow browsers to prefetch specific pages or render them in the background. With this change, the as, crossorigin, pr, and type attributes can be passed in addition to the URLs/hosts.

Props peterwilsoncc, swissspidy.
Fixes #38121.

This ticket was mentioned in Slack in #core-themes by davidakennedy. View the logs.

8 years ago

#19 @desrosj
4 years ago

  • Keywords has-dev-note added; needs-dev-note removed

Linking the dev note that was published here for reference:

Note: See TracTickets for help on using tickets.