HTTP headers | X-DNS-Prefetch-Control - GeeksforGeeks

30 Dec, 2019
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.
File objects like style sheets, images, JavaScript, etc are pre-fetched in the background. Pre-fetching is done in the background as it is possible that the DNS will be handled by the time the specified items are needed or the user clicks a URL, this reduces latency.
Syntax:
X-DNS-Prefetch-Control: on
X-DNS-Prefetch-Control: on
X-DNS-Prefetch-Control: off
X-DNS-Prefetch-Control: off
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.
Examples:
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/">
<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">
<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
Firefox
Opera
HTTP-headers
Picked
Technical Scripter
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Difference between var, let and const keywords in JavaScript
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to create footer to stay at the bottom of a Web page?
Differences between Functional Components and Class Components in React
Node.js fs.readFileSync() Method