Resource Hints in WordPress 4.6

Last updated on by admin

Resource Hints is a W3C specification that defines the dns-prefetch, preconnect, prefetch, and prerender relationships of the HTML Link Element (<link>). These can be used to assist the browser in the decision process of which origins it should connect to, and which resources it should fetch and preprocess to improve page performance.

In the upcoming WordPress 4.6, there will be a simple API to register and use resource hints.

By default, wp_resource_hints() prints hints for (the CDN) and for all scripts and styles which are enqueued from external hosts.

Developers can use the wp_resource_hints filter to add custom domains and URLs for dns-prefetch, preconnect, prefetch or prerender. Here is how the filter works:

function my_custom_resource_hints( $hints, $relation_type )
    if ( 'dns-prefetch' === $relation_type ) {
        $hints[] = '//';
    else if ( 'prerender' === $relation_type ) {
        $hints[] = '';
    return $hints;
add_filter( 'wp_resource_hints', 'my_custom_resource_hints', 10, 2 );
special SiteGround WordPress hostingspecial Bluehost WordPress hosting

Leave a Reply

Your email address will not be published. Required fields are marked *