Controlling DNS prefetching

Controlling DNS prefetching

IN THIS ARTICLE

  1. Background
  2. Configuring prefetching in the browser
  3. Controlling prefetching from content
    1. Turning on and off prefetching
    2. Forcing lookup of specific hostnames
  4. See also

As of version 3.5, Firefox supports DNS prefetching. This is a feature by which Firefox proactively performs 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 already have been resolved by the time the referenced items are actually needed.  This reduces latency when, for example, the user actually 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 when, for example, the user clicks a link can be reduced significantly (on the order of a second, in some cases).

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 delays during the process of fetching content.

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

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.  This can be done by setting thenetwork.dns.disablePrefetch preference to true.

Also, by default, prefetching of embedded link hostnames is not performed on documents loaded over HTTPS.  This can be changed by setting thenetwork.dns.disablePrefetchFromHTTPS preference to false.

Controlling prefetching from content

Content providers have some control over the prefetching process as well.  This is compatible with how Google Chrome handles DNS prefetching control.

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="http://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, 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 home page of a site to force pre-resolution of domain names that are referenced frequently throughout the site even though they‘re not used on the home page itself.  This will improve overall site performance even though the performance of the home page may not be affected.

See also

时间: 2024-10-10 18:45:01

Controlling DNS prefetching的相关文章

MDN &gt; Web technology for developers &gt; HTTP

The Hypertext Transfer Protocol (HTTP) is an application-layer protocol for transmitting hypermedia documents. It is used for communication between web browsers and web servers, though in principle it can be used for other purposes as well. It follow

关于dns-prefetch的详细资料

最近在看别的网站的源码,看到了一个新鲜东西(大多数网站都没有使用的一个东西----dns-prefetch)百度,阿里巴巴,淘宝,天猫,谷歌都使用了这个东西,如下: 为什么这些巨头公司会使用这个呢?我就搜了很多资料,其中有一篇介绍了它的底层原理: DNS优化的原理和方法 这篇文章介绍的非常好.主要内容为: DNS 实现域名到IP的映射.通过域名访问站点,每次请求都要做DNS解析.目前每次DNS解析,通常在200ms以下.针对DNS解析耗时问题,一些浏览器通过DNS Prefetch 来提高访问的

HTML5 prefetch即预加载

原文地址 声明:此文带着自己的理解,不完全按原文翻译 prefetch 即预加载,在用户需要前我们就将所需的资源加载完毕. 有了浏览器缓存,为何还需要预加载? 用户可能是第一次访问网站,此时还无缓存 用户可能清空了缓存 缓存可能已经过期,资源将重新加载 用户访问的缓存文件可能不是最新的,需要重新加载 Chrome 的预加载技术 现在的 chrome 聪明到根据你的浏览记录,预测到你可能访问或搜索哪些网站,在你打开网站之前就加载好了一些资源了.举个栗子,当你在搜索框输入 "amaz" 时

前端优化:DNS预解析提升页面速度

在网页体验中我们常会遇到这种情况,即在调用百度联盟.谷歌联盟以及当前网页所在域名外的域名文件时会遇到请求延时非常严重的情况.那么有没有方法去解决这种请求严重延时的现象呢? 一般来说这种延时的原因不会是对方网站带宽或者负载的原因,那么到底是什么导致了这种情况呢.假设是DNS的问题,因为DNS解析速度很可能是造成资源延时的最大原因.于是在页面header中添加了以下代码(用以DNS预解析): <meta http-equiv="x-dns-prefetch-control" cont

DNS Prefetch初认识

今天在看一个后台框架时,发现这样的代码: <link rel="dns-prefetch" href="//0.s3.envato.com"><link rel="dns-prefetch" href="//thumb-tf.s3.envato.com" /><link rel="dns-prefetch" href="//user-profile.s3.envato

DNS预解析 dns-prefetch

1.DNS 是什么? Domain Name System,域名系统,作为域名和IP地址相互映射的一个分布式数据库. DNS大家都懂,那么浏览器访问域名的时候,是需要去解析一次DNS,也就是把域名 google.com解析到对应的ip地址上,修改本机hosts就是主动的影响DNS解析. 既然要解析就会损耗时间,对于前端特别是移动端而言,分秒必争,所以浏览器厂商-Chrome最想搞了这个新功能. 定义--浏览器根据自定义的规则,提前去解析后面可能用到的域名,来加速网站的访问速度. DNS Pref

DNS预解析和浏览器并发连接数

当浏览器请求一个URL的时候,通过firebug我们可以发现大概有以下几个过程:阻挡.域名解析.建立连接.发送请求.等待响应.接收数据.后面四个跟用户的网络情况和你的服务器处理速度有关,本文重点说说前两个. 1.阻挡:解决方案--提高浏览器并发连接数 阻挡:不同的浏览器对单个域名的最大并发连接数有一定的限制,HTTP/1.0和HTTP/1.1也不相同.比如HTTP/1.1协议下,IE6的并发连接数限制是2个:而在HTTP/1.0下,IE6的并发连接数可以达到4个.在其它浏览器也有类似的限制,一般

DNS 预解析

DNS 解析也是需要时间的,可以通过预解析的方式来预先获得域名所对应的 IP. <link rel="dns-prefetch" href="//yuchengkai.cn"> DNS Prefetch,即DNS预获取,是前端优化的一部分.一般来说,在前端优化中与 DNS 有关的有两点: 一个是减少DNS的请求次数,另一个就是进行DNS预获取 . DNS 作为互联网的基础协议,其解析的速度似乎很容易被网站优化人员忽视.现在大多数新浏览器已经针对DNS解析

CDN与DNS知识汇总

在性能优化的时候,比较常见的一个建议是,把资源部署在CDN上,那么问题来了,CDN是什么?这样做有什么好处? DNS 我们先讲一下域名系统DNS(Domain Name System)吧. 他是一个分布式数据库,功能是联系域名和ip地址.域名与ip的对应关系,被称为记录(record),可分为各种类型 A: Address,域名指向的IP地址,一个域名可以有多个A记录. NS:Name Server,保存下一级域名信息的服务器地址 MX:Mail eXchange,接受电子邮件的服务器地址 CN