Make WordPress Core

Changeset 38122


Ignore:
Timestamp:
07/20/2016 06:18:30 PM (8 years ago)
Author:
ocean90
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

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

    r38121 r38122  
    28032803    $hints = array(
    28042804        'dns-prefetch' => wp_dependencies_unique_hosts(),
    2805         'preconnect'   => array( 's.w.org' ),
     2805        'preconnect'   => array(),
    28062806        'prefetch'     => array(),
    28072807        'prerender'    => array(),
    28082808    );
     2809
     2810    /*
     2811     * Add DNS prefetch for the Emoji CDN.
     2812     * The path is removed in the foreach loop below.
     2813     */
     2814    /** This filter is documented in wp-includes/formatting.php */
     2815    $hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
    28092816
    28102817    foreach ( $hints as $relation_type => $urls ) {
  • trunk/tests/phpunit/tests/general/resourceHints.php

    r38100 r38122  
    3232
    3333    function test_should_have_defaults_on_frontend() {
    34         $expected = "<link rel='preconnect' href='http://s.w.org'>\n";
     34        $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n";
    3535
    3636        $this->expectOutputString( $expected );
     
    4040
    4141    function test_dns_prefetching() {
    42         $expected = "<link rel='dns-prefetch' href='//wordpress.org'>\n" .
     42        $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n" .
     43                    "<link rel='dns-prefetch' href='//wordpress.org'>\n" .
    4344                    "<link rel='dns-prefetch' href='//google.com'>\n" .
    44                     "<link rel='dns-prefetch' href='//make.wordpress.org'>\n" .
    45                     "<link rel='preconnect' href='http://s.w.org'>\n";
     45                    "<link rel='dns-prefetch' href='//make.wordpress.org'>\n";
    4646
    4747        add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ), 10, 2 );
     
    6868
    6969    function test_prerender() {
    70         $expected = "<link rel='preconnect' href='http://s.w.org'>\n" .
     70        $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n" .
    7171                    "<link rel='prerender' href='https://make.wordpress.org/great-again'>\n" .
    7272                    "<link rel='prerender' href='http://jobs.wordpress.net'>\n" .
     
    9494
    9595    function test_parse_url_dns_prefetch() {
    96         $expected = "<link rel='dns-prefetch' href='//make.wordpress.org'>\n" .
    97                     "<link rel='preconnect' href='http://s.w.org'>\n";
     96        $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n" .
     97                    "<link rel='dns-prefetch' href='//make.wordpress.org'>\n";
    9898
    9999        add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ), 10, 2 );
     
    116116    function test_dns_prefetch_styles() {
    117117        $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com'>\n" .
    118                     "<link rel='preconnect' href='http://s.w.org'>\n";
     118                    "<link rel='dns-prefetch' href='//s.w.org'>\n";
    119119
    120120        $args = array(
     
    135135    function test_dns_prefetch_scripts() {
    136136        $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com'>\n" .
    137                     "<link rel='preconnect' href='http://s.w.org'>\n";
     137                    "<link rel='dns-prefetch' href='//s.w.org'>\n";
    138138
    139139        $args = array(
     
    152152
    153153    function test_dns_prefetch_scripts_does_not_included_registered_only() {
    154         $expected = "<link rel='preconnect' href='http://s.w.org'>\n";
     154        $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n";
    155155        $unexpected = "<link rel='dns-prefetch' href='//wordpress.org'>\n";
    156156
Note: See TracChangeset for help on using the changeset viewer.