[wp-trac] [WordPress Trac] #34292: Support for DNS Prefetching & Prerender

WordPress Trac noreply at wordpress.org
Mon Jul 11 10:40:27 UTC 2016


#34292: Support for DNS Prefetching & Prerender
-------------------------------------------------+-------------------------
 Reporter:  bhubbard                             |       Owner:
     Type:  feature request                      |  voldemortensen
 Priority:  normal                               |      Status:  closed
Component:  Script Loader                        |   Milestone:  4.6
 Severity:  normal                               |     Version:
 Keywords:  has-patch has-unit-tests needs-dev-  |  Resolution:  fixed
  note needs-docs                                |     Focuses:
                                                 |  performance
-------------------------------------------------+-------------------------

Comment (by swissspidy):

 @superpoincare Ah, gotcha! From my understanding, it won't hurt the
 performance. From the spec:

 > The user agent should attempt to initiate a preconnect and perform the
 full connection handshake (DNS+TCP for HTTP, and DNS+TCP+TLS for HTTPS
 origins) whenever possible, but is allowed to elect to perform a partial
 handshake (DNS only for HTTP, and DNS or DNS+TCP for HTTPS origins), or
 skip it entirely, due to resource constraints or other reasons.

 Even when enqueued in the head of the document, the resource hints will be
 delivered to the browser much earlier because their higher up in the
 source and therefore likely in another HTTP packet. Already being able to
 perform all necessary handshakes only benefits the actual retrieval of the
 assets later on.

 In addition to that, keep in mind that `wp_resource_hints()` doesn't add
 `preconnect` entries for scripts/styles. It adds `dns-prefetch` entries,
 which means the browser only performs a DNS lookup for these resources. So
 even if `preconnect` for scripts/styles enqueued in the header would be
 bad, `dns-prefetch` would cause less harm.

 If you're worried about that, you can always use the `wp_resource_hints`
 filter to remove these:

 {{{#!php
 <?php
 function trac34292_example_resource_hints( $hints, $relation_type ) {
     if ( 'dns-prefetch' === $relation_type ) {
         return array_diff( $hints, wp_get_dependencies_unique_hosts() );
 // Note the function name might be different
     }

     return $hints;
 }

 add_filter( 'wp_resource_hints', 'trac34292_example_resource_hints', 10, 2
 );
 }}}

 Even on larger sites there are usually few external scripts and styles in
 the header, so I don't think there's much of an issue here though.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34292#comment:52>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list