🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

X DNS Prefetch Control

HTTP Header

Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The HTTP X-DNS-Prefetch-Control response header manages DNS prefetching, a process where browsers proactively resolve domain names for links that users might click on as well as URLs for items referenced within the document, such as images, CSS files, JavaScript files, and others.

The goal is to perform prefetching in the background so that the DNS resolution is completed before the browser needs to access these resources.
This approach helps to reduce latency, making page interactions like clicking a link faster.

Syntax

Syntax

http
X-DNS-Prefetch-Control: on
X-DNS-Prefetch-Control: off

Directives

Directives

on

Enables DNS prefetching. This feature allows browsers to resolve domain names in advance, improving website load times. Browsers typically perform this automatically if they support it, even when this header is not included.

off

Disables DNS prefetching, which can be useful if you don’t control the links on the pages or wish to prevent potential leakage of information to certain domains.

Example

DNS requests are very small in terms of bandwidth, but latency can be quite high, especially on mobile networks. By proactively prefetching DNS results, we can significantly reduce latency, especially when a user clicks on a link. In some cases, this can cut down delays by as much as a second.

Some browsers implement this prefetching by resolving domain names concurrently with fetching the page content, instead of serially. This means the DNS resolution process doesn’t add to the page load time, making browsing faster. As a result, page load times—particularly on mobile networks—can be noticeably improved. When domain names for images are resolved in advance, pages loading numerous images can see a 5% or greater reduction in load time.

In most cases, you don’t need to manually manage prefetching. However, users can choose to disable it. On Firefox, this can be done by setting the preference network.dns.disablePrefetch to true. Additionally, by default, prefetching of embedded link hostnames is not performed on pages loaded over HTTPS. This can be changed in Firefox by setting network.dns.disablePrefetchFromHTTPS to false.

Examples

Turning on and off prefetching

Prefetching can be controlled via HTTP headers or meta tags within documents. To disable prefetching, use the following meta tag:

<p><meta http-equiv=”x-dns-prefetch-control” content=”off” /></p>

Reversing this setting to enable prefetching is done by changing the content to "on".

Forcing lookup of specific hostnames

To force DNS resolution of particular hostnames without specifying full URLs, use the <link> element with rel set to dns-prefetch. For example:

<p><link rel=”dns-prefetch” href=”https://www.mozilla.org” /></p>

This will pre-resolve the domain www.mozilla.org. Additionally, to resolve hostnames using only the hostname, prefix it with two slashes:

<p><link rel=”dns-prefetch” href=”//www.mozilla.org” /></p>

This prefetching approach is useful on high-traffic sites to resolve frequently used domains even if they are not directly linked in the homepage. It improves overall site performance.

Specifications

This feature is not currently part of any formal specification.

How to Modify Header using Requestly

Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the X-DNS-Prefetch-Control header. This can help you control whether browsers perform DNS prefetching on your site during development or testing. Steps to Modify the X-DNS-Prefetch-Control Header:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. Add a new header modification:
    • Under “Action”, select “Add” or “Override”.
    • In the “Header Name” field, enter X-DNS-Prefetch-Control.
    • In the “Header Value” field, enter on to enable or off to disable DNS prefetching.
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-website.com/*).
  5. Save the rule.

Once set up, Requestly will inject the X-DNS-Prefetch-Control header into all matching requests, letting you enable or disable DNS prefetching to optimize performance or troubleshoot networking issues.

You might need to modify this header to control DNS prefetching behavior in browsers, which can impact page load times and resource usage. This helps ensure your website loads efficiently and securely under different conditions.