← Glossary

What Is DNS Prefetching?

DNS prefetching resolves a hostname before a resource request or navigation needs it. A browser may do this speculatively or follow a dns-prefetch hint, reducing later lookup delays while potentially revealing interest in a domain the user never visits.

Updated:

DNS prefetching is speculative name resolution: the browser looks up the IP address of a hostname it expects to need soon, so that when a request to that host is actually made the address is already in the cache. The expectation can come from the browser itself, which may resolve the hostnames of links on a page in case the user clicks one, or from the page, which can declare a dns-prefetch resource hint for an origin it will shortly fetch resources from. The page is making a prediction, not requiring immediate work. The browser decides whether to act on the hint, which concerns name resolution rather than a resource download. It does not itself open a connection to the target web server or fetch page content.

How Speculative Resolution Works

A DNS lookup can be a serial step when a hostname's address is not already available. MDN's performance guide explains that when a browser requests a resource from a cross-origin server, that server's domain name must be resolved to an IP address before the request can be issued, and that while caching helps, resolution can add significant latency for sites that open connections to many third parties. Prefetching moves that step earlier, overlapping it with work the browser is already doing, such as parsing the page or waiting for the user.

The explicit form is a link element in the document head, for example <link rel="dns-prefetch" href="https://fonts.example.com">, or the same hint delivered as an HTTP Link header. If it accepts the hint, the browser resolves the hostname, caches a usable answer, and can reuse it when the page later requests a font, script or image from that origin. The implicit form needs no markup: MDN's description of the X-DNS-Prefetch-Control header notes that browsers proactively perform domain name resolution on links the user may choose to follow as well as URLs for items referenced by the document, in browsers that support this behaviour. The header is non-standard: support and defaults vary. Where honoured, a page can request that implicit prefetching be disabled with the header or an equivalent meta tag, which is useful when it contains many links to domains it does not control.

Speculative DNS resolution also has browser-specific privacy controls: MDN records that prefetching of embedded link hostnames is not performed by default on documents loaded over HTTPS, a behaviour it documents for Firefox, which has a preference to change it. Explicit dns-prefetch hints can be used on HTTPS pages; this documented distinction concerns automatic link speculation, not a universal browser rule.

DNS Prefetch Compared With Preconnect and Preload

Resource hints form a ladder of increasing commitment.

HintWhat the browser does earlyCostBest for
dns-prefetchResolves the hostnameDNS resolution work, potentially involving several record queriesMany third-party origins that may be used
preconnectResolves the hostname and starts connection establishment, which for HTTP/1.1 or HTTP/2 over HTTPS includes TCP and TLSA held-open socket and handshake workA few critical origins that will certainly be used soon
preloadFetches a specific resource the current page needsA full downloadResources discovered late by the parser, such as fonts referenced in CSS

MDN's preconnect documentation describes it as preemptively performing part or all of the handshake, DNS plus TCP for HTTP and DNS plus TCP plus TLS for HTTPS, and warns that preconnecting many third-party domains can be counterproductive because each held connection consumes resources. Its advice is to reserve preconnect for the most critical connections and use dns-prefetch for the rest. Sites sometimes pair both hints for compatibility with clients that support DNS prefetching but not preconnect; usefulness depends on the actual browser audience. Fonts and other resources fetched in anonymous mode need the crossorigin attribute on the preconnect hint, so that any prepared connection matches the eventual fetch's credentials mode. The dns prefetch vs preconnect choice is therefore about certainty and count: resolve names for origins you might use, connect to origins you will use, and keep the second list short.

Performance Benefits

The saving is the duration of a DNS lookup on the critical path, which varies with caching, resolver proximity and network conditions. On a page that pulls fonts, analytics, advertising and media from separate origins, removing that delay from each third-party request can shave a noticeable amount from the time to first render or first interaction. The benefit disappears when the hostname is already cached, when resolution was not delaying the critical resource, or when the hinted origin is never used, and it is nil for the page's own origin, since MDN notes that the site's own domain was resolved before the browser saw the hint. Measuring the effect with and without the hints, rather than assuming it, is the reliable approach; an ignored hint provides no performance gain, while excessive markup still adds maintenance and document overhead.

Privacy Trade-offs

Every lookup tells the resolver a hostname, and a prefetched lookup tells it about a hostname the user has not visited and may never visit. For implicit prefetching of links, this means the resolver, and anyone able to observe unencrypted DNS on the path, learns the domains a page links to as well as the ones the user chose. MDN frames the off setting of X-DNS-Prefetch-Control around exactly this concern: it is useful when a site does not control the links on its pages or does not want to leak information to those domains. The HTTPS default exception for link prefetching is a related mitigation. Encrypted DNS limits who on the path can see the queries but not what the chosen resolver learns, and a resolver that is outside a VPN or proxy path receives prefetched names as readily as ordinary ones. Browsers that partition DNS caches by top-level site, as Firefox has done since its network partitioning work, reduce cross-site cache-timing signals by separating cache state rather than sharing one lookup history.

Limits of the Hint

DNS prefetching is advisory and bounded. Browsers can ignore hints, and their scheduling, user settings and resource budgets determine whether speculative work happens. The cached answer has a time to live after which it must be refreshed, so a hint placed too early can expire before it is used. Prefetching does not warm a connection, does not negotiate TLS and does not fetch anything; those belong to preconnect and preload. It does nothing for same-origin requests and little for origins already in the cache. Adding hints for every origin can produce resolver traffic without proportional benefit. Unused hints may expose names and consume resources without helping a later request. Used for a short list of genuinely likely third-party origins, with preconnect reserved for the certain ones, DNS prefetching removes a small, serial delay from requests the page was going to make anyway.

Frequently asked questions

Does DNS prefetch open a full connection?

No. It only resolves the hostname to an address and caches the answer. Opening a TCP connection and performing the TLS handshake is what preconnect does, and fetching an actual resource is what preload does.

Can a browser ignore the hint?

Yes. A dns-prefetch hint is advisory. Browser settings, implementation choices and available resources determine whether and when it runs. Check actual network behaviour rather than treating the markup as proof that resolution occurred or that a future request will be faster.

Can prefetch reveal interest in a domain?

Yes. If a lookup leaves the local cache, the resolver can learn a hostname the user may never visit. The non-standard X-DNS-Prefetch-Control header can limit automatic link speculation where supported, but its behaviour should be checked in the browsers you serve.

Should dns-prefetch be used for the page's own origin?

Usually there is no benefit: the current page's hostname has already been resolved to load that page. Concentrate on other hostnames likely to be needed soon. A different scheme or port alone does not create a new DNS name to resolve.

When is preconnect better than dns-prefetch?

When the origin will certainly be used soon and its resources are on the critical path, such as a font or script host. Preconnect does the DNS, TCP and TLS work early but holds a connection open, so MDN advises limiting it to the most critical origins and using dns-prefetch for the rest.