How to Speed up WordPress upto 200% with One Powerful Hack

How to make your Website 200% Faster with One Powerful Trick

As a WordPress Admin, Are you really fed up with the slow speed of your website?

Or you want to change your host to some costly host only for speed?

Wait,

6 to 7 month before most of my time waste on to find tricks about how to speed up WordPress.

Some of the tricks work and some not.

But I am unable to meet my desired speed.

Until,

I found a new way to instantly improve any website with one simple trick.

This called DNS prefetch.

When you Google about DNS prefetch, many bloggers not recommended this method.

They are true only if you configure it not correct.

In this article, I’ll show you how to configure it correctly even if you are a newbie to WordPress or web sites stuff.

But before going to configuration part, I’ll give you some basic knowledge about how it’s work and what is it.

What is DNS Prefetching & Working

DNS prefetching is trying to resolve domain names before a user tries to follow a link.

This is accomplished using the computer’s built-in DNS resolution mechanism. Once a domain name has been resolved, if we do navigate to that domain, there will be no effective delay due to DNS resolution time. While downloading speed remains the same, looking up the IP address beforehand will save you an easily perceptible second or two when going from page to page.

How much navigation time will a user save can range from average savings of about 200 milliseconds for the non-cached content to one to two seconds for the worst DNS resolution delays.

Source

Time save by DNS Prefetch

So, How much time saved ny dns prefetch method.

Here I share two images,

First captured without DNS prefetch and Second after applying DNS Prefetch.

For this Screenshots, I am using a dummy website.

Without DNS Prefetch

This image taken when I am not applying DNS Prefetch code into my website. Check the result here.
After DNS Prefetch Applied

This image taken when DNS Prefetch code applied in my website. Check the Result here.

You clearly see It’s saved almost 300ms.

What that means,

My site now almost 200% faster than before.

How to Apply DNS Prefetch in WordPress

Simply put this code in your function.php, always use a child theme so when update available for your main theme it does not mess the customization.

//* Adding DNS Prefetching
function stb_dns_prefetch() {
echo '<meta http-equiv="x-dns-prefetch-control" content="on">
<link rel="dns-prefetch" href="//fonts.googleapis.com" />
<link rel="dns-prefetch" href="//fonts.gstatic.com" />
<link rel="dns-prefetch" href="//0.gravatar.com/" />
<link rel="dns-prefetch" href="//2.gravatar.com/" />
<link rel="dns-prefetch" href="//1.gravatar.com/" />';
}
add_action('wp_head', 'stb_dns_prefetch', 0);

This code added into in your WordPress header and looks like below code.

if you want to add an extra domain in this code, simply copy any one line and changed it with your need.

Keep in mind the last link comes with '; so don’t break it, otherwise, your website displays strange error.

<meta http-equiv="x-dns-prefetch-control" content="on">
<link rel="dns-prefetch" href="//fonts.googleapis.com" />
<link rel="dns-prefetch" href="//fonts.gstatic.com" />
<link rel="dns-prefetch" href="//0.gravatar.com/" />
<link rel="dns-prefetch" href="//2.gravatar.com/" />
<link rel="dns-prefetch" href="//1.gravatar.com/" />

How to Apply DNS Prefetch in Any Website

Simply copy the below code, change it with your need and paste it below <head>

<meta http-equiv="x-dns-prefetch-control" content="on">
<link rel="dns-prefetch" href="//fonts.googleapis.com" />
<link rel="dns-prefetch" href="//fonts.gstatic.com" />
<link rel="dns-prefetch" href="//0.gravatar.com/" />
<link rel="dns-prefetch" href="//2.gravatar.com/" />
<link rel="dns-prefetch" href="//1.gravatar.com/" />

Conclusion

This is really powerful code and it’s make or break your website speed.

Only use those domains in DNS Prefetch which is actually used in your website, like gravatar.

If you find another method which is helpful in website speed other than DNS Prefetch, Share with us.

Share with your friends, because sharing is caring.

6 thoughts on “How to Speed up WordPress upto 200% with One Powerful Hack

  1. Hi Shaikh Masood,

    Website speed metrics looks amazing, I am using MyThemeShop WordPress which does’nt have child theme and I don’t want to mess up with errors, is there any WordPress plugin which do the same thing?, anyway thanks for sharing the valuable information about this tweak, see you soon with another article.

    • Shaikh Masood Alam

      You can use Header and Footer Plugin for adding any code in your header or footer.
      Use this code.

      <meta http-equiv="x-dns-prefetch-control" content="on">
      <link rel="dns-prefetch" href="//fonts.googleapis.com" />
      <link rel="dns-prefetch" href="//fonts.gstatic.com" />
      <link rel="dns-prefetch" href="//0.gravatar.com/" />
      <link rel="dns-prefetch" href="//2.gravatar.com/" />
      <link rel="dns-prefetch" href="//1.gravatar.com/" />
  2. Hi there !

    this is very good post on making wordpress website faster. using CDN with this also helps a lot in increasing website speed.

    Thanks for sharing with us.

  3. Hiii bro
    thanx you soo much for sharing this knowledge with us, as i was facing the same problem, but now i hope your suggestion will definetely help me.
    thanx

  4. Hey There ,
    Can You Help Me out.
    How Can I check which url should be added there?

    • Shaikh Masood Alam

      Check your blog using https://tools.pingdom.com/, and find external domains. Add them in your codes.

Leave a Comment

13 Shares
Tweet
Share
+1
Share
Pin