Bobcares

Add DNS prefetch for WordPress | How to?

by | Nov 6, 2022

Let’s check on how to Add DNS prefetch for WordPress by our support team, with help of our WordPress Support Services at Bobcares.

DNS prefetch for WordPress

Add DNS prefetch for WordPress

Domain Name System popularly known as DNS prefetching. It’s a process to resolve domain names before users request them. This helps to make websites load faster and increase overall performance.

 

This is a method to resolve the domain name or a page before any user tries to visit the link. There is a normal DNS resolution mechanism for systems that complete this task. During this resolution, no connection to Google used.

 

The browsers like google chrome, firefox cache the contents of a page in the background, making it quickly displayable to the user if they click on that specific link.

 

Once a domain name has been resolved and the user follows the link, then there will be no effective delay due to the DNS resolution. And the final result is a quick loading of a page or domain.

 

However, the process of resolution is done with an expectation followed by the user in the next step.

 

How to set up DNS prefetching in WordPress

 

Follow the below steps to enable DNS prefetching in WordPress:

 

1. Install a DNS Prefetch plugin

 

One of the easiest ways to implement DNS prefetching in WordPress is to use a plugin. This will save your theme file edits.

 

The best plugin to handle this is Perfmatters. It’s a premium plugin with many features to speed up a WordPress website. Another alternative is WP Rocket.

 

For Perfmatters, you will have to download the plugin from their site, Install, and activate to your WordPress dashboard.

 

If you don’t want to use the plugin, but to do it manually jump straight to point 4.

 

2. Add domains to prefetch

 

After installing and activating the Perfmatters plugin. Go to plugin settings >> click on the extra tap. Here you can add domain names to prefetch.

 

However, you should only add one domain per line following the pattern as shown:

 
//fonts.googleapis.com
//www.google-analytics.com
//cdnjs.cloudflare.com
//www.googletagmanager.com
 

For WP Rocket. Go to the Preload tab >> scroll down to Prefetch DNS Requests. There you can add URLs that you want to prefetch. As the same pattern like above.

 

3. Save changes

 

Make sure you save changes. That is all.

 

4. Add DNS prefetching in WordPress manually

 

To add DNS prefetching in WordPress manually, without any plugin then you will have to edit your theme’s functions.php code.

 

Add the below code to your functions.php file. Below example, I have added Google Tag Manager, Google Analytics, and Google fonts as a guide. You can add more or edit it.

 
//* DNS Prefetching
function dns_prefetch() {
    echo '<meta http-equiv="x-dns-prefetch-control" content="on">
<link rel="dns-prefetch" href="https://www.google-analytics.com" />
<link rel="dns-prefetch" href="https://www.googletagmanager.com" />
<link rel="dns-prefetch" href="https://fonts.googleapis.com" />
}
add_action('wp_head', 'dns_prefetch', 0);
 

Add a new line like this:

 
<link rel="dns-prefetch" href="https://DOMAIN.com" />
 

[Looking for a solution to another query? We are just a click away.]

 

Conclusion

To sum up, from DNS prefetch for WordPress article we have enabled DNS prefetching in WordPress. This method resolves the domain name or website pages before the user tries to visit the link. 
 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.