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.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF