• Resolved Ramanan

    (@superpoincare)


    Hi Ryan,

    WordPress 4.6 has support for resource hints.

    So it does dns-prefetch for s.w.org.

    For those who disable emojis, there’s no need for this.

    Can disabling dns-prefetch to s.w.org be added to your plugin?

    (One reason it may not be consistent with this plugin’s aim is that s.w.org may be used by plugins such as Jetpack).

    https://www.ads-software.com/plugins/disable-emojis/

Viewing 15 replies - 1 through 15 (of 19 total)
  • I just came over to this support page to request the same thing. There is more info on this here: https://www.ads-software.com/support/topic/remove-the-new-dns-prefetch-code

    Do you think filtering out the s.w.org prefetching is a good fit for this plugin, Ryan?

    Thanks!

    Thread Starter Ramanan

    (@superpoincare)

    Christee,

    This is the way to do it:

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

    ie:

    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 );

    @ramanan – thanks, but that removes all prefetches, not just the emoji one. $hints, in my case, looks like this when it is passed in:

    array(3) { [0]=> string(20) "fonts.googleapis.com" [1]=> string(16) "cdn.jsdelivr.net" [2]=> string(40) "https://s.w.org/images/core/emoji/2/svg/" }

    Only key 2 should be removed.

    Replacing the if in the function recommended above with this:

    if ( 'dns-prefetch' === $relation_type ) {
    		$matches = preg_grep('/emoji/', $hints);
    		return array_diff( $hints, $matches );
        }

    does the trick. But my php is not strong, so this may not be the best or right way to do this.

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    Support for this has been added into the latest version.

    Fantastic! Yes, the new version solves it.
    Thanks for being so responsive!

    I’m thinking the problem has risen again in WP 4.7

    Can anyone confirm?

    Thread Starter Ramanan

    (@superpoincare)

    Haven’t checked but it’s because the emoji folder has changed:

    See line 5008.

    https://github.com/WordPress/WordPress/blob/c2d709e9d6cbe7f9b3c37da0a7c9aae788158124/wp-includes/formatting.php#L5008

    /2.2.1/ was earlier just /2/

    Thanks Ramanan, I updated the plugin to the new folder path as you pointed out and it did indeed correct the problem.

    I’ll wait for Ryan to update the plugin through WP instead of manually changing them all.

    Thanks again!

    Thread Starter Ramanan

    (@superpoincare)

    Thanks for confirming it work, semrocc.

    A suggestion for Ryan for the update.

    Since not everyone might update to 4.7, in the simplest solution, the plugin will need to keep track of the version. So folder /2/ for some versions and /2.2.1/ after that. But beyond a point, it will be difficult to keep track of this and become cumbersome.

    So the solution will need to do something other than this.

    Thread Starter Ramanan

    (@superpoincare)

    Or else I can raise a ticket on core.trac to ask WordPress to modify their code, so that disabling it becomes simpler. Is that a good idea?

    Yes Ramanan, raising a ticket would probably be a good thing. Dealing with path changes on a regular basis doesn’t make sense and would become cumbersome as you pointed out.

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    Sorry, I didn’t see this thread update until now. I’ll take a look at this and try to push out an update shortly.

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    Sorry for the long delay in fixing this. If any of you ever notice me miss a fix like this, please pester me via Twitter ??

    I may have seen some emails about this, but just thought it was people using older versions of the plugin and so not paid it the attention I should have.

    I’m uploading a new version just now, which fixes this problem. This is a crude solution though, and it will break if the URL is updated again. I’ll try to come up with an upgradeable solution so that this doesn’t keep happening regularly.

    As of 4.7, the “hints” code above does not work. I’d like to remove all the dns-prefetch stuff that jetpack is adding.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Disable dns-prefetch of s.w.org’ is closed to new replies.