X-DNS-Prefetch-Control
Speculative DNS resolution for links on a page is controlled by the unofficial X-DNS-Prefetch-Control response header, which enables or disables browser DNS prefetching.
Note
The "X-" naming convention for HTTP headers, "X" referring to "experimental", has been deprecated and needs to be transitioned to the formal naming convention for HTTP headers.
Usage
DNS prefetching is a browser optimization where the browser resolves domain names for hyperlinks on a page before the user clicks them. Each DNS lookup adds latency, often tens of milliseconds, and prefetching eliminates this delay by completing the resolution in advance.
The X-DNS-Prefetch-Control header gives site operators explicit control over this behavior. Pages with many external links benefit from prefetching because the resolved addresses are ready when the user navigates. Pages handling sensitive information disable prefetching to prevent DNS queries from leaking the domains referenced on the page, as each prefetch sends a DNS query visible to network observers and DNS resolvers.
Browsers generally enable DNS prefetching by default for pages loaded over HTTP and disable prefetching for pages loaded over HTTPS. This header overrides the default in either direction.
The <link rel="dns-prefetch"> HTML element provides
per-link control for individual domains, while
X-DNS-Prefetch-Control sets the page-wide default.
Values
on
The on value enables DNS prefetching for all links on the
page. Browsers resolve the domain names of linked resources
in the background as the page loads.
off
The off value disables DNS prefetching entirely. No
background DNS resolution occurs for links on the page. This
is appropriate for privacy-sensitive pages, login forms, or
pages listing user-specific content where the linked domains
reveal information about the page contents.
Example
Enabling DNS prefetching on a page with many external links to improve perceived navigation speed:
X-DNS-Prefetch-Control: on
Disabling DNS prefetching on a page handling sensitive data, preventing DNS queries from revealing linked domains:
X-DNS-Prefetch-Control: off
Note
DNS prefetch, preconnect, and preload serve
different stages of resource loading. DNS
prefetch resolves only the domain name.
Preconnect (<link rel="preconnect">)
completes DNS resolution, TCP handshake, and
TLS negotiation. Preload
(<link rel="preload">) goes further and
fetches the resource itself. DNS prefetch is
the lightest option and appropriate for links
a visitor might click. Preconnect and preload
suit resources known to be needed on the
current page.