The X-DNS-Prefetch-Control is an HTTP response type header that informs the browser whether DNS prefetch to be executed or not. Turning it on may not work as many browsers may not support it in all the situations. Turning it off should disable in all supported browsers. Most of the browsers will ignore this header as they don’t do DNS prefetching.
Directives: This header accepts two directives as mentioned above and described below:
- on: This directive enables pre-fetching of the DNS. This is what browsers do when this header is not available, if they support the function.
- off: This directive disables pre-fetching of DNS. This is useful if you don’t monitor the pages reference, or if you know that you don’t want to leak information to those websites.
- Specific hostnames force lookup: By using the rel attribute on the <link> component with a link type of DNS-Prefetch, you can force the lookup of certain hostnames without providing specific anchors. In this example, the domain name “www.geeksforgeeks.org” will be pre-resolved.
<link rel="dns-prefetch" href="https://www.geeksforgeeks.org/">
Likewise, the link component is used to resolve hostnames without having a full URL, but only by adding dual slashes before the hostname:
<link rel="dns-prefetch" href="//www.geeksforgeeks.org/">
- Turning on and off prefetching: You can also use the HTTP-Equiv parameter on the component to send the X-DNS-Prefetch-Control headers server-side or from individual files. Forced prefetching of hostnames could be helpful, for instance, on a site’s homepage to compel pre-resolution of domain names often cited throughout the site even though they are not used on the home page itself.
<meta http-equiv="x-dns-prefetch-control" content="off">
<meta http-equiv="x-dns-prefetch-control" content="on">
Note: DNS requests are very small in terms of bandwidth, but latency can be very high for mobile networks.
Supported Browsers: The browsers supported by X-DNS-Prefetch-Control header are listed below:
- Google Chrome