Revision 1142949 of X-DNS-Prefetch-Control

  • Revision slug: Web/HTTP/Headers/X-DNS-Prefetch-Control
  • Revision title: X-DNS-Prefetch-Control
  • Revision id: 1142949
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment
Tags: 

Revision Content

{{HTTPSidebar}}

The X-DNS-Prefetch-Control HTTP response header controls DNS prefetching, 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 {{glossary("DNS")}} is likely to have been resolved by the time the referenced items are needed. This reduces latency when the user clicks a link.

Header type {{Glossary("Response header")}}
{{Glossary("Forbidden header name")}} no

Syntax

X-DNS-Prefetch-Control: on
X-DNS-Prefetch-Control: off

Directives

on
Enables DNS prefetching.
off
Disables DNS prefetching.

Description

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 some browsers 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 {{glossary("HTTPS")}}. On Firefox, this can be changed by setting the network.dns.disablePrefetchFromHTTPS preference to false.

Examples

Turning on and off prefetching

You can either send the X-DNS-Prefetch-Control header server-side, or from individual documents, using the {{ htmlattrxref("http-equiv", "meta") }} attribute on the {{ HTMLElement("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

You can force the lookup of specific hostnames without providing specific anchors using that hostname by using the {{ htmlattrxref("rel","link") }} attribute on the {{ HTMLElement("link") }} element with a link type of dns-prefetch:

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

In this example, the domain name "www.spreadfirefox.com" will be pre-resolved.

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

Revision Source

<div>{{HTTPSidebar}}</div>

<p>The <strong><code>X-DNS-Prefetch-Control</code></strong> HTTP response header controls DNS prefetching, 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.</p>

<p>This prefetching is performed in&nbsp;the background, so that the {{glossary("DNS")}} is likely to have been resolved by the time the referenced items are needed. This reduces latency when the user clicks a link.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Header type</th>
   <td>{{Glossary("Response header")}}</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Forbidden header name")}}</th>
   <td>no</td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
X-DNS-Prefetch-Control: on
X-DNS-Prefetch-Control: off
</pre>

<h3 id="Directives">Directives</h3>

<dl>
 <dt>on</dt>
 <dd>Enables DNS prefetching.</dd>
 <dt>off</dt>
 <dd>Disables DNS prefetching.</dd>
</dl>

<h2 id="Description">Description</h2>

<p>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.</p>

<p>The implementation of this prefetching in some browsers 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.</p>

<p>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.</p>

<h3 id="Configuring_prefetching_in_the_browser">Configuring prefetching in the browser</h3>

<p>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 <code>network.dns.disablePrefetch</code> preference to <code>true</code>.</p>

<p>Also, by default, prefetching of embedded link hostnames is not performed on documents loaded over {{glossary("HTTPS")}}. On Firefox, this can be changed by setting the <code>network.dns.disablePrefetchFromHTTPS</code> preference to <code>false</code>.</p>

<h2 id="Examples">Examples</h2>

<h3 id="Turning_on_and_off_prefetching">Turning on and off prefetching</h3>

<p>You can either send the&nbsp;<code>X-DNS-Prefetch-Control</code> header server-side, or from individual documents, using the {{ htmlattrxref("http-equiv", "meta") }} attribute on the {{ HTMLElement("meta") }} element, like this:</p>

<pre class="brush: html">
&lt;meta http-equiv="x-dns-prefetch-control" content="off"&gt;
</pre>

<p>You can reverse this setting by setting <code>content</code> to "<code>on</code>".</p>

<h3 id="Forcing_lookup_of_specific_hostnames">Forcing lookup of specific hostnames</h3>

<p>You can force the lookup of specific hostnames without providing specific anchors using that hostname by using the {{ htmlattrxref("rel","link") }} attribute on the {{ HTMLElement("link") }} element with a <a href="/en-US/docs/Web/HTML/Link_types">link type</a> of <code>dns-prefetch</code>:</p>

<pre class="brush: html">
&lt;link rel="dns-prefetch" href="http://www.spreadfirefox.com/"&gt;
</pre>

<p>In this example, the domain name "<a class="linkification-ext external" href="http://www.spreadfirefox.com" title="Linkification: http://www.spreadfirefox.com">www.spreadfirefox.com</a>" will be pre-resolved.</p>

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

<pre class="brush: html">
&lt;link rel="dns-prefetch" href="//www.spreadfirefox.com"&gt;
</pre>

<p>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.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a class="external" href="http://bitsup.blogspot.com/2008/11/dns-prefetching-for-firefox.html">DNS&nbsp;Prefetching for Firefox (blog post)</a></li>
 <li><a class="external" href="http://dev.chromium.org/developers/design-documents/dns-prefetching">Google Chrome handles DNS prefetching control</a></li>
</ul>
Revert to this revision