From 5aee8db5a2281e48aaa8a008da29c5e39f4b58b4 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Thu, 18 Aug 2022 08:43:19 +0000 Subject: [PATCH] Script Loader: Remove default DNS prefetch entry for s.w.org. A default DNS prefetch entry for s.w.org was previously included to save a few ms in case an emoji is used that is not supported by the browser. It appears this use case doesn't justify a prefetch to s.w.org on every WordPress website. This changesets removes `emoji_svg_url` prefetch from `wp_resource_hints()`. It also updates unit tests in `Tests_General_wpResourceHints` by removing `test_should_have_defaults_on_frontend()` entirely and removing s.w.org prefetch from expected output of ten other test functions. Plugin authors can use the `wp_resource_hints` filter if they need to re-add the DNS prefetch entry for s.w.org. Follow-up to [37920], [38122]. Props joelhardi, superpoincare, jhabdas, garrett-eclipse, sabernhardt, SergeyBiryukov. Fixes #40426. See #37387. git-svn-id: https://develop.svn.wordpress.org/trunk@53904 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/general-template.php | 7 ---- .../phpunit/tests/general/wpResourceHints.php | 35 ++++++------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 3f042865ad..444a2dcddf 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -3317,13 +3317,6 @@ function wp_resource_hints() { '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/13.0.0/svg/' ); - foreach ( $hints as $relation_type => $urls ) { $unique_urls = array(); diff --git a/tests/phpunit/tests/general/wpResourceHints.php b/tests/phpunit/tests/general/wpResourceHints.php index 1761196b2c..03a4c024e0 100644 --- a/tests/phpunit/tests/general/wpResourceHints.php +++ b/tests/phpunit/tests/general/wpResourceHints.php @@ -30,17 +30,8 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { parent::tear_down(); } - public function test_should_have_defaults_on_frontend() { - $expected = "\n"; - - $this->expectOutputString( $expected ); - - wp_resource_hints(); - } - public function test_dns_prefetching() { - $expected = "\n" . - "\n" . + $expected = "\n" . "\n" . "\n"; @@ -70,8 +61,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { * @ticket 37652 */ public function test_preconnect() { - $expected = "\n" . - "\n" . + $expected = "\n" . "\n" . "\n" . "\n"; @@ -98,8 +88,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { } public function test_prerender() { - $expected = "\n" . - "\n" . + $expected = "\n" . "\n" . "\n"; @@ -124,8 +113,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { } public function test_parse_url_dns_prefetch() { - $expected = "\n" . - "\n"; + $expected = "\n"; add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_long_urls' ), 10, 2 ); @@ -145,8 +133,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { } public function test_dns_prefetch_styles() { - $expected = "\n" . - "\n"; + $expected = "\n"; $args = array( 'family' => 'Open+Sans:400', @@ -164,8 +151,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { } public function test_dns_prefetch_scripts() { - $expected = "\n" . - "\n"; + $expected = "\n"; $args = array( 'family' => 'Open+Sans:400', @@ -185,7 +171,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { * @ticket 37385 */ public function test_dns_prefetch_scripts_does_not_include_registered_only() { - $expected = "\n"; + $expected = ''; $unexpected = "\n"; wp_register_script( 'jquery-elsewhere', 'https://wordpress.org/wp-includes/js/jquery/jquery.js' ); @@ -202,7 +188,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { * @ticket 37502 */ public function test_deregistered_scripts_are_ignored() { - $expected = "\n"; + $expected = ''; wp_enqueue_script( 'test-script', 'http://example.org/script.js' ); wp_deregister_script( 'test-script' ); @@ -215,7 +201,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { * @ticket 37652 */ public function test_malformed_urls() { - $expected = "\n"; + $expected = ''; // Errant colon. add_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_errant_colon' ), 10, 2 ); @@ -250,8 +236,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase { * @ticket 38121 */ public function test_custom_attributes() { - $expected = "\n" . - "\n" . + $expected = "\n" . "\n" . "\n" . "\n";