• Hello,

    How can I remove the new dns-prefecth code added to my website since the new update ?

    <link rel='dns-prefetch' href='//fonts.googleapis.com'>
    <link rel='dns-prefetch' href='//s.w.org'>

    Thanks

Viewing 15 replies - 1 through 15 (of 23 total)
  • I’m also trying to remove this and tried to remove the filter like this:

    remove_action( 'wp_head', 'dns-prefetch' );

    It didn’t work though. Please let me know if you find a solution.

    It looks like this is a known bug:
    https://core.trac.www.ads-software.com/ticket/37694

    remove_action( 'wp_head', 'wp_resource_hints', 2 );

    But can I ask why? It’s there to improve the performance of your site.

    Thank you Jacob, that worked perfect.

    I’m fine using dns-prefetch for asset related URL’s, but it seems like thes.w.org link is unnecessary since it’s not related to any JS or CSS on the website.

    I believe that’s for emoji. It can be removed separately:

    add_filter( 'emoji_svg_url', '__return_false' );

    There’s also another filter, wp_resource_hints, that can be used to filter out/add specific URLs.

    Thank you Jacob, we’re already using this to remove emoji:

    // Remove emoji script
    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
    remove_action( 'wp_print_styles', 'print_emoji_styles' );

    And the additional of your code helps remove this extra dns-prefetch:

    add_filter( 'emoji_svg_url', '__return_false' );

    Thank you!

    Thread Starter olorin

    (@olorin)

    Thanks Jacob !

    But can I ask why? It’s there to improve the performance of your site.

    Sure, I don’t use googlefonts or emoji on my website.

    The only URL that WordPress seems to add in itself is the emoji one. The rest are pulled from wp_enqueue_style() and wp_enqueue_script(). It looks like a plugin or theme you’re using is loading a Google font.

    Does anyone know if using this will adversely impact other DNS prefetching which we do with mod_pagespeed ?

    We don’t use emoji or google fonts so want to also remove the
    <link rel='dns-prefetch' href='//s.w.org'>

    Will this ONLY solution only remove that single element?
    remove_action( 'wp_head', 'wp_resource_hints', 2 );

    thanks ??

    Ramanan

    (@superpoincare)

    You can do it using the code here:

    https://core.trac.www.ads-software.com/ticket/37694

    That is:

    function remove_dns_prefetch( $hints, $relation_type ) {
        if ( 'dns-prefetch' === $relation_type ) {
            return array_diff( wp_dependencies_unique_hosts(), $hints );
        }
    
        return $hints;
    }
    
    add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );

    Okay, just as FYI, both solutions “work” – but we are using the latter ( thanks @ramanan).

    This works:
    remove_action( 'wp_head', 'wp_resource_hints', 2 );

    this also works, but seems way more specific, which is gooder! ??

    function remove_dns_prefetch( $hints, $relation_type ) {
        if ( 'dns-prefetch' === $relation_type ) {
            return array_diff( wp_dependencies_unique_hosts(), $hints );
        }
    
        return $hints;
    }
    
    add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );

    Since this is specific to WordPress, should not impact external pre-fetch injections from mod_pagespeed, which we have off for upgrading at the moment so can’t test my original worry on the first example code.

    ??

    WordPress really should have a toggle in the general setting “Use emojis” yes/no. For a blog about candy, sure. For a pure business news portal, not really needed.

    none works for me, is there any other solution. please give if any.

    I ran W3C’s Link Checker and it keeps giving me an error on the dns-prefetch line for google fonts api:

    https://fonts.googleapis.com is 404 Not Found

    Am trying to understand the issue – does that mean the prefetch isn’t working? Or is W3C Validator checking the wrong thing?

    Thanks!
    Abby

    @abbey the prefetch is just to find the ip address of the server where the resources are hosted. It doesn’t actually retrieve any files.

    If a site has a lot of assets then the browser can lookup the ip address of external hosts whilst downloading other assets, and then when it comes to downloading the ones from that host, it doesn’t need to perform a dns lookup as it already knows the location and can directly request the needed assets.

    The prefetch would be fine, as ‘robwent’ mentioned – just the address of the server – but it has been throwing 404 errors. Try the URL – Google cannot find the requested URL on the server ?? oh no! Now what?

    A 404 is irrelevant.
    You are missing the point of what this is for.
    Google doesn’t go to the URL in the prefetch link and get a 404 page. It looks up the IP of the domains server so that when it needs a resourse from that domain its faster to get it as the DNS location has already been found.

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘Remove the new dns-prefetch code’ is closed to new replies.