Make WordPress Core

Changeset 53904


Ignore:
Timestamp:
08/18/2022 08:43:19 AM (4 years ago)
Author:
audrasjb
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r53888 r53904  
    33183318        );
    33193319
    3320         /*
    3321          * Add DNS prefetch for the Emoji CDN.
    3322          * The path is removed in the foreach loop below.
    3323          */
    3324         /** This filter is documented in wp-includes/formatting.php */
    3325         $hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/13.0.0/svg/' );
    3326 
    33273320        foreach ( $hints as $relation_type => $urls ) {
    33283321                $unique_urls = array();
  • trunk/tests/phpunit/tests/general/wpResourceHints.php

    r52010 r53904  
    3131        }
    3232
    33         public function test_should_have_defaults_on_frontend() {
    34                 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
    35 
    36                 $this->expectOutputString( $expected );
    37 
    38                 wp_resource_hints();
    39         }
    40 
    4133        public function test_dns_prefetching() {
    42                 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    43                                         "<link rel='dns-prefetch' href='//wordpress.org' />\n" .
     34                $expected = "<link rel='dns-prefetch' href='//wordpress.org' />\n" .
    4435                                        "<link rel='dns-prefetch' href='//google.com' />\n" .
    4536                                        "<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
     
    7162         */
    7263        public function test_preconnect() {
    73                 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    74                                         "<link rel='preconnect' href='//wordpress.org' />\n" .
     64                $expected = "<link rel='preconnect' href='//wordpress.org' />\n" .
    7565                                        "<link rel='preconnect' href='https://make.wordpress.org' />\n" .
    7666                                        "<link rel='preconnect' href='http://google.com' />\n" .
     
    9989
    10090        public function test_prerender() {
    101                 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    102                                         "<link rel='prerender' href='https://make.wordpress.org/great-again' />\n" .
     91                $expected = "<link rel='prerender' href='https://make.wordpress.org/great-again' />\n" .
    10392                                        "<link rel='prerender' href='http://jobs.wordpress.net' />\n" .
    10493                                        "<link rel='prerender' href='//core.trac.wordpress.org' />\n";
     
    125114
    126115        public function test_parse_url_dns_prefetch() {
    127                 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    128                                         "<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
     116                $expected = "<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
    129117
    130118                add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_long_urls' ), 10, 2 );
     
    146134
    147135        public function test_dns_prefetch_styles() {
    148                 $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
    149                                         "<link rel='dns-prefetch' href='//s.w.org' />\n";
     136                $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n";
    150137
    151138                $args = array(
     
    165152
    166153        public function test_dns_prefetch_scripts() {
    167                 $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
    168                                         "<link rel='dns-prefetch' href='//s.w.org' />\n";
     154                $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n";
    169155
    170156                $args = array(
     
    186172         */
    187173        public function test_dns_prefetch_scripts_does_not_include_registered_only() {
    188                 $expected   = "<link rel='dns-prefetch' href='//s.w.org' />\n";
     174                $expected   = '';
    189175                $unexpected = "<link rel='dns-prefetch' href='//wordpress.org' />\n";
    190176
     
    203189         */
    204190        public function test_deregistered_scripts_are_ignored() {
    205                 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
     191                $expected = '';
    206192
    207193                wp_enqueue_script( 'test-script', 'http://example.org/script.js' );
     
    216202         */
    217203        public function test_malformed_urls() {
    218                 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
     204                $expected = '';
    219205
    220206                // Errant colon.
     
    251237         */
    252238        public function test_custom_attributes() {
    253                 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    254                                         "<link rel='preconnect' href='https://make.wordpress.org' />\n" .
     239                $expected = "<link rel='preconnect' href='https://make.wordpress.org' />\n" .
    255240                                        "<link crossorigin as='image' pr='0.5' href='https://example.com/foo.jpeg' rel='prefetch' />\n" .
    256241                                        "<link crossorigin='use-credentials' as='style' href='https://example.com/foo.css' rel='prefetch' />\n" .
Note: See TracChangeset for help on using the changeset viewer.