Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!

DNS prefetching is a feature by which browsers proactively perform domain name resolution on both links that the user may choose to follow as well as URLs for items referenced by the document, including images, CSS, JavaScript, and so forth.

This prefetching is performed in the background, so that the DNS is likely to have been resolved by the time the referenced items are needed.  This reduces latency when the user clicks a link.

Background

DNS requests are very small in terms of bandwidth, but latency can be quite high, especially on mobile networks.  By speculatively prefetching DNS results, latency can be reduced significantly at certain times, such as when the user clicks the link. In some cases, latency can be reduced by a second.

The implementation of this prefetching in Firefox allows domain name resolution to occur in parallel with (instead of in serial with) the fetching of actual page content.  By doing this, the high-latency domain name resolution process doesn't cause any delay while fetching content.

Page load times -- especially on mobile networks -- can be measurably improved in this way.  If the domain names for images can be resolved in advance of the images being requested, pages that load many images can see an improvement of 5% or more in the time of loading images.

Configuring prefetching in the browser

In general, you don't need to do anything to manage prefetching.  However, the user may wish to disable prefetching.  On Firefox, this can be done by setting the network.dns.disablePrefetch preference to true.

Also, by default, prefetching of embedded link hostnames is not performed on documents loaded over HTTPS.  On Firefox, this can be changed by setting the network.dns.disablePrefetchFromHTTPS preference to false.

Controlling prefetching from content

Content providers have some control over the prefetching process as well.

Turning on and off prefetching

First of all, a server can opt out of DNS prefetching by serving content with the x-dns-prefetch-control: HTTP header set to "off".

This can also be done from individual documents, using the http-equiv attribute on the <meta> element, like this:

<meta http-equiv="x-dns-prefetch-control" content="off">

You can reverse this setting by setting content to "on".

Forcing lookup of specific hostnames

The content provider can force the lookup of specific hostnames without providing specific anchors using that hostname by using the rel attribute on the <link> element with a link type of dns-prefetch:

<link rel="dns-prefetch" href="https://www.spreadfirefox.com/">

In this example, Firefox will pre-resolve the domain name "www.spreadfirefox.com".

Similarly, the link element can be used to resolve hostnames without providing a complete URL, but only, by preceding the hostname with two slashes:

<link rel="dns-prefetch" href="//www.spreadfirefox.com">

Forced prefetching of hostnames might be useful, for example, on the homepage of a site to force pre-resolution of domain names that are referenced frequently throughout the site even though they are not used on the home page itself.  This will improve the overall performance of site even though the performance of the home page may not be affected.

See also

ドキュメントのタグと貢献者

タグ: 
 このページの貢献者: snatalini, rolfedh, PushpitaPikuDey, hiddo32, fscholz, teoli, davidillsley, Znerd, Sheppy
 最終更新者: snatalini,