How to Reduce DNS Lookups

Back to homepage

How to Reduce DNS Lookups

What is a DNS lookup?
A DNS stands for Domain Name System which maintains records pertaining to which domain name maps to which IP address. This is commonly compared to a phonebook in that people’s names are associated to a particular phone number. More specifically, a DNS lookup is the process of finding which IP the domain name belongs to. This system allows us to use user-friendly domains such as while still being able to communicate with the server that stores the requested information.
The process of performing the DNS lookup falls on the responsibility of the browser. Upon accessing a web page, the browser finds all resources which require a DNS lookup and must wait until the lookup completes before it can download anything. According to YSlow, DNS lookups on average take between 20-120 milliseconds to complete.
This article will cover how to reduce DNS lookups in order to help improve overall page load times.

  1. Reduce the number of hostnames
    Simply reducing the number of hostnames that are used in order to generate your web page is the most straightforward method. Go through your site and audit the hostnames and assets that are triggering requests.
    For example, if you are making external requests to generate social icon buttons, fonts, libraries, etc. these all require a DNS lookup. Determine if all of these external resources are in fact necessary and evaluate the cost/benefit ratio between keeping the external resources and the additional loading time that this creates.
  2. Host third party resources locally
    Hosting third party resources locally allows you to reduce DNS lookups while garnering better control of how the resource is delivered in general. Using this method, you can define how long the asset should be cached, whether it should be delivered by a CDN, and much more.
    Download the files that are being referenced to an external resource and host them on your origin server or CDN. This way, resources will be retrieved without having to make an additional DNS lookup. Storing them on a CDN will help further improve loading times as users will be delivered content from the closest edge server. Additionally, hosting files on a CDN will help take a load off of the origin server.
    This method however should not be used in all cases. For example, third party scripts are often times updates frequently therefore if you’re hosting the asset locally or on your CDN, you may not be using the most updated script. However, in certain instances, there are ways to host third party scripts and check periodically for updates. Learn more about how to do this for Gravatars, Google Analytics, and font libraries.
    Additionally, check out our complete guide to optimizing third party scripts and learn more.
    Improve the speed of remaining DNS lookups#
    To reduce DNS lookups by following the suggestions above is a good step towards optimizing the number of lookups required. However, what about optimizing the DNS lookups that are necessary to render the site. There are a number of ways to improve these as well, including:
  3. Use DNS cache to your advantage
    Thankfully, due to DNS caching DNS lookups are not required every time a browser requests an asset. As long as the cache hasn’t expired, the DNS server’s cache can provide the hostname to the browser without having to look it up. What defines the length of DNS cache is what’s called TTL or time to live.

Not all DNS records should be cached equally. It is based on the type of record you use that should define what its TTL should be. There are no values which are “set in stone” however the following provide a good baseline:
• CNAME Records – 24 hours
• A and AAAA Records – Anywhere between 5 minutes to 1 hour
• TXT Records – 12 hours
• MX Records – 12 hours
Note that in many cases (like in the screenshot above) TTL values are shown in seconds instead of minutes or hours so be sure to do the conversion before you define a value.

  1. DNS prefetching#
    Use DNS prefetching to allow the browser to perform DNS lookups in the background while the user browses the current page. Therefore, when the user clicks on a particular link with prefetched resources, they won’t need to wait for the DNS lookup to occur. The image below shows how prefetching in general works.

DNS prefetching is very easy to configure and can be added to your link attributes as follows:

Read more about prefetching in our complete prefetching guide.

  1. Minimize the number of CNAME records
    CNAME records produce an additional lookup which creates a small amount of added wait time. Having a few CNAME records is normal and you won’t experience much change. However, if your setup has multiple CNAME records it may be time to consider removing a few from your DNS setup. That being said, you can use ANAME records instead which give you the same functionality as a CNAME record, but at the root level. Therefore, instead of the following lookup process with a CNAME record: 43200 IN 43200 IN A
    An ANAME record will return the following: 43200 IN A
    Furthermore, Cloudflare also provides a solution to this that they call CNAME Flattening.
  2. Defer parsing of JavaScript
    Deferring the parsing of JavaScript won’t necessarily speed up your DNS lookups however it will optimize your above-the-fold content. Therefore visitors will start to see your website being loaded sooner, which helps improve perceived performance. Additionally, deferring the parsing of JavaScript will allow for the important content to first be loaded and then load the non-critical JS
    To learn more about how to defer parsing JavaScript, check out this guide.
  3. Use a fast DNS provider
    Lastly, use a fast DNS provider when looking to optimize your DNS lookups. Although many DNS providers are available, they are not all created equal. Check out our complete guide to the 10 best DNS providers to learn more about what’s available and how they compare. Do your research before making a final decision and run some performance tests to compare them against your current DNS provider.
    Keeping an eye on and reducing DNS lookups is essential if you want to optimize your site’s performance. With so many third party services now available, it’s easy to stack up a slurry of external requests which really adds a lot of latency for your website visitors. If you receive a recommendation from Google PageSpeed or GTmetrix to reduce DNS lookups, use the above suggestions to help resolve this recommendation and further improve your site’s performance.

MSSQL ‘Recovery Pending’ Problem

To solve MSSQL Recovery Pending problem follow the steps Stop SQL Remove transaction log on this database Change database mode to emergency mode and restart database After restart run this commands for your database ALTER DATABASE [DB_Name] SET EMERGENCY; DBCC checkdb...

Uninstall Edge from Windows 10

To uninstall Microsoft Edge from Windows 10 Close the Edge browser on your computer.Open the file explorer. You can easily do this by right clicking the Windows start button and then selecting File Explorer.In the file explorer, select This PC.Once in this PC navigate...

High Performance is not shown on PowerSetting

Right click StartSelect RunType regedit and press enter to open the registry editorGo to the folder: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\PowerOn the right, check one of the keys called CsEnabledClick on that keyChange the value from 1 to 0Restart your...

Convert an MBR disk into a GPT disk

Converting using the Windows interface Back up or move the data on the basic MBR disk you want to convert into a GPT disk.If the disk contains any partitions or volumes, right-click each and then click Delete Partition or Delete Volume.Right-click the...

MacBook Virtual Keyboard solution for broken touchbars

The solution was in Karabiner. Download Karabiner. Downloaded the "Map fn + number keys to their corresponding function keys" plugin If you need help you can reach us free online remote support over Anydesk.

Prevent deleting Google Chrome history

It is absolutely possible in windows. You can do it by adding a policy to the chrome browser using Registry Editor. Click the Windows button and search for Registry EditorRight-click on it and select Run as administrator.Navigate to HKEY_LOCAL_MACHINE >...

Lenovo 13 Thinkpad series camera freezes after 2 sec

Its realy big problem for Lenovo, when you started the camera, it freeze 2-3 seconds later. Thats the solve 🙂 Press Windows key + R, type regedit, and press Enter.Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Media Foundation\Platform.Right-click on the...

Print non-white colors in your PDF file as only black

On Windows, you can print all of the non-white colors in your PDF file as black, resulting in a simple monochrome printout. Printing as black is useful for printing PDFs that contain text only, or for printing engineering drawings that have lightly colored lines....

Change default browser page Edge to Explorer

Open Microsoft Edge browserGo to SettingsSelect Default browser tab optionin the internet Explorer compatibility setting, you will see an option "Let Internet Explorer open sites in Microsoft Edge" , the default value is Incompatible Sites only(Recommended). You can...

Mac SMC reset

Just hold down Shift+Option+Control when the laptop is off for 7 seconds. It will turn on. After 7 seconds keep holding the keys down and additionally press the power button (Touch ID). The laptop will turn off. Wait a few seconds then turn it on normally, and your...