How to Implement DNS Prefetching in WordPress For Faster Loading
Got fed up with the slow site? You can easily increase some performance grades in the gtmerix, tool.pingdom, google pagespeed insight by Implementing DNS Prefetching in WordPress Website. So before I jump into deep let’s have some basic description.
What is DNS Prefetching?
DNS prefetch is a technique by which we forced the browser to perform DNS lookup in the background Before the user follows a link. Which will ultimately affect your website loading time and increase your performance. This will reduce the timing in resolving the domains. This can easily be done by adding link relation as rel=”dns-prefetch” with the link inside the header of the website for 3rd party domain. For example <link rel=”dns-prefetch” href=”//example.com”>
You might be interested in reading which is the best caching Plugin, Fomo Plugins and live chat plugins
How to Implement DNS Prefetching in WordPress?
There are many ways to perform this action. Most 2 ways we can follow.
#1 Method – By using Plugins
There are many plugins that can help you implement this action on your website. So I will show you 3 plugins how you can do this.
1. Pre* Party Resource Hints – Install this plugin >>> Click on setting >>> Then insert the URL in the given field >>> and then click on insert.
2. Wp-rocket – Inside the Prefetch DNS requests dialog box. You need to add your URL without using HTTP or HTTPS
3. perfmatters – Once you activate the plugin their will an Extra Option Tab inside that tab you will find a dialog box to enter the URL as shown in the image
There are many plugins that can perform this action like autoptimize and many more.
#2 Method – Without using Plugins
You need to paste the following code inside the function.php page. But make sure you should use your 3rd party URL in the place of 3rd-party-domain1.com. So don’t forget to replace the URL inside the code.
Note – In the following code last code end with ‘; so whatever your last domain is there you should do it properly.
function gomahamaya_dns_prefetch() { echo '<meta http-equiv="x-dns-prefetch-control" content="on"> <link rel="dns-prefetch" href="//3rd-party-domain1.com" /> <link rel="dns-prefetch" href="//3rd-party-domain2.com" /> <link rel="dns-prefetch" href="//3rd-party-domain3.com" />'; // last step has '; make sure it should be therein last } add_action('wp_head', 'gomahamaya_dns_prefetch', 0); Final result
Now How to find which all domains need to be Pre fetched
For finding out the name of the domain we will recommend you to use tool.pingdom. Scan your website first. Once you are done scanning. You need to find the ” Requests by domain ” section and collect all 3rd party DNS requests.
List of famous Prefetch DNS requests domains are
//fonts.googleapis.com
//apis.google.com
//ajax.googleapis.com
//maps.googleapis.com
//google-analytics.com
//api.pinterest.com
//cdnjs.cloudflare.com
//connect.facebook.net
//i.ytimg.com
//fonts.gstatic.com
//www.googletagmanager.com
Now bingo Finally we learned How to Implement DNS Prefetching in WordPress For Faster Loading.
It’s a great information. Thanks for sharing.
Hi there Rahul, your article is a peace of heaven…tnx you