Script Loader: Use `dns-prefetch` for the Emoji CDN.

* `preconnect` will be potentially pretty heavy on the CDN. With the Unicode 9.0 emoji update, almost all browsers will trigger the `preconnect`.
* `preconnect` only opens one connection, but `s.w.org` is HTTP/1.1, so the browser will use the preconnected connection for the first emoji, then it has to open new connections for subsequent emoji.

Also use the same URL as we use for the `emoji_svg_url` filter. This will print the hint for the correct CDN in case someone uses a custom CDN.

Props peterwilsoncc.
Fixes #37387.

git-svn-id: https://develop.svn.wordpress.org/trunk@38122 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling 2016-07-20 18:18:30 +00:00
parent c750ff2d3c
commit 63b7f3da1b
2 changed files with 18 additions and 11 deletions

View File

@ -2802,11 +2802,18 @@ function wp_site_icon() {
function wp_resource_hints() {
$hints = array(
'dns-prefetch' => wp_dependencies_unique_hosts(),
'preconnect' => array( 's.w.org' ),
'preconnect' => array(),
'prefetch' => array(),
'prerender' => array(),
);
/*
* Add DNS prefetch for the Emoji CDN.
* The path is removed in the foreach loop below.
*/
/** This filter is documented in wp-includes/formatting.php */
$hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
foreach ( $hints as $relation_type => $urls ) {
/**
* Filters domains and URLs for resource hints.

View File

@ -31,7 +31,7 @@ class Tests_WP_Resource_Hints extends WP_UnitTestCase {
}
function test_should_have_defaults_on_frontend() {
$expected = "<link rel='preconnect' href='http://s.w.org'>\n";
$expected = "<link rel='dns-prefetch' href='//s.w.org'>\n";
$this->expectOutputString( $expected );
@ -39,10 +39,10 @@ class Tests_WP_Resource_Hints extends WP_UnitTestCase {
}
function test_dns_prefetching() {
$expected = "<link rel='dns-prefetch' href='//wordpress.org'>\n" .
$expected = "<link rel='dns-prefetch' href='//s.w.org'>\n" .
"<link rel='dns-prefetch' href='//wordpress.org'>\n" .
"<link rel='dns-prefetch' href='//google.com'>\n" .
"<link rel='dns-prefetch' href='//make.wordpress.org'>\n" .
"<link rel='preconnect' href='http://s.w.org'>\n";
"<link rel='dns-prefetch' href='//make.wordpress.org'>\n";
add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ), 10, 2 );
@ -67,7 +67,7 @@ class Tests_WP_Resource_Hints extends WP_UnitTestCase {
}
function test_prerender() {
$expected = "<link rel='preconnect' href='http://s.w.org'>\n" .
$expected = "<link rel='dns-prefetch' href='//s.w.org'>\n" .
"<link rel='prerender' href='https://make.wordpress.org/great-again'>\n" .
"<link rel='prerender' href='http://jobs.wordpress.net'>\n" .
"<link rel='prerender' href='//core.trac.wordpress.org'>\n";
@ -93,8 +93,8 @@ class Tests_WP_Resource_Hints extends WP_UnitTestCase {
}
function test_parse_url_dns_prefetch() {
$expected = "<link rel='dns-prefetch' href='//make.wordpress.org'>\n" .
"<link rel='preconnect' href='http://s.w.org'>\n";
$expected = "<link rel='dns-prefetch' href='//s.w.org'>\n" .
"<link rel='dns-prefetch' href='//make.wordpress.org'>\n";
add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ), 10, 2 );
@ -115,7 +115,7 @@ class Tests_WP_Resource_Hints extends WP_UnitTestCase {
function test_dns_prefetch_styles() {
$expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com'>\n" .
"<link rel='preconnect' href='http://s.w.org'>\n";
"<link rel='dns-prefetch' href='//s.w.org'>\n";
$args = array(
'family' => 'Open+Sans:400',
@ -134,7 +134,7 @@ class Tests_WP_Resource_Hints extends WP_UnitTestCase {
function test_dns_prefetch_scripts() {
$expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com'>\n" .
"<link rel='preconnect' href='http://s.w.org'>\n";
"<link rel='dns-prefetch' href='//s.w.org'>\n";
$args = array(
'family' => 'Open+Sans:400',
@ -151,7 +151,7 @@ class Tests_WP_Resource_Hints extends WP_UnitTestCase {
}
function test_dns_prefetch_scripts_does_not_included_registered_only() {
$expected = "<link rel='preconnect' href='http://s.w.org'>\n";
$expected = "<link rel='dns-prefetch' href='//s.w.org'>\n";
$unexpected = "<link rel='dns-prefetch' href='//wordpress.org'>\n";
wp_register_script( 'jquery-elsewhere', 'https://wordpress.org/wp-includes/js/jquery/jquery.js' );