Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#37317 closed defect (bug) (fixed)

Change priority of `wp_resource_hints()` to print them earlier

Reported by: ocean90's profile ocean90 Owned by: ocean90's profile ocean90
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.6
Component: General Keywords: has-patch commit
Focuses: performance Cc:

Description

As noted in https://wordpress.org/support/topic/ordering-of-dns-prefetch-preconnect?replies=2, the resource hints should be printed before scripts and styles are returned.

The current priority is 10 for wp_head and for the admin we're using admin_head which runs after admin_print_scripts. We can lower the priority to 1 for the front end and should change the admin hook to admin_print_styles.

Attachments (3)

37317.diff (2.0 KB) - added by swissspidy 8 years ago.
37317.2.diff (3.0 KB) - added by swissspidy 8 years ago.
37317.3.diff (2.7 KB) - added by ocean90 8 years ago.

Download all attachments as: .zip

Change History (13)

@swissspidy
8 years ago

#1 @swissspidy
8 years ago

  • Keywords has-patch added; needs-patch removed

#2 @ocean90
8 years ago

  • Keywords needs-patch added; has-patch removed

Discovered a few more things:

  • Resource hints are missing in the Customizer.
  • Resource hints are missing on wp-login.php.
  • The filter in wp-admin/includes/admin-filters.php should be in wp-includes/default-filters.php, this will fix the Customizer.

@swissspidy
8 years ago

#3 @swissspidy
8 years ago

  • Keywords has-patch added; needs-patch removed

What do you think of 37317.2.diff?

#4 follow-up: @peterwilsoncc
8 years ago

  • Keywords needs-refresh added

In 37317.2.diff customizer outputs the hints twice, above DOCTYPE declaration.

Additional thoughts

  • On wp_head setting the priority to 2 seems a surer way of ensuring it follows the enqueue action.
  • Using 1000 as a magic number for admin_enqueue_scripts doesn't thrill me, a low number on admin_print_scripts seems more likely to get the desired result.

#5 in reply to: ↑ 4 ; follow-up: @ocean90
8 years ago

Replying to peterwilsoncc:

  • Using 1000 as a magic number for admin_enqueue_scripts doesn't thrill me, a low number on admin_print_scripts seems more likely to get the desired result.

Did you mean admin_print_styles here? Because admin_print_scripts runs after styles are printed.

#6 in reply to: ↑ 5 @peterwilsoncc
8 years ago

Replying to ocean90:

Did you mean admin_print_styles here? Because admin_print_scripts runs after styles are printed.

I did, yes.

@ocean90
8 years ago

#7 @ocean90
8 years ago

37317.3.diff uses customize_controls_print_styles and admin_print_styles with a ! is_customize_preview() condition to prevent adding hints twice to the customizer.

#8 @peterwilsoncc
8 years ago

  • Keywords commit added; needs-refresh removed

Looks good to me.

#9 @swissspidy
8 years ago

  • Owner set to ocean90
  • Status changed from new to assigned

#10 @ocean90
8 years ago

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

In 38046:

Resource Hints: Increase priority of wp_resource_hints() so hints get printed before scripts and styles.

Also run wp_resource_hints() on the login screen and in the customizer.

Props swissspidy.
Fixes #37317.

Note: See TracTickets for help on using tickets.