How to Implement DNS Prefetching in WordPress For Faster Loading
Got fed up slow site ? You can easily increase some performance grade in gtmerix , tool.pingdom , google pagespeed insight by Implementing DNS Prefetching in WordPress Website . So before i jump into deep lets 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 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 interest in reading which is 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 follows .
#1 Method – By using Plugins
There are many plugins which can help you implement this action in your website . So i will showing your on 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 a 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 which can perform this action like autoptimize and many more .
#2 Method – Without using Plugins
You need 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 you 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 domain need to be Pre fetched
For finding out the name of domain we will recommend you to use tool.pingdom . Scan you website first . Once you are done scanning . You need to find ” Requests by domain ” section and collect all 3rd party dns request .
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 learnt How to Implement DNS Prefetching in WordPress For Faster Loading .
It’s a great information. Thanks for sharing.