dns 预取/预解析主机名 - 效果如何? [英] dns prefetch / pre-resolve hostname - how effective?

查看:26
本文介绍了dns 预取/预解析主机名 - 效果如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读它的工作原理,但一直在努力理解它.

I've been reading up on how this works but am struggling to make sense of it.

据我所知,如果我在网页的头部设置了 <link rel="dns-prefetch" href="//ajax.googleapis.com"/>应该看到更快的请求完成是我引用了这个域上的任何资产.[ref]

From what I can tell if I set <link rel="dns-prefetch" href="//ajax.googleapis.com" /> in the head of my webpage I should see a faster request completion is I reference any assets on this domain. [ref]

现在有两个问题困扰着我:

Now there are two issues which are currently bothering me:

我的意思是,如果我使用 Google 的 CDN 获取 jQuery 在我网站的每个页面上 会在上面添加 有什么区别吗?或者,如果我没有在我的主页上引用 CDN,而是在所有其他页面上,它只会有帮助吗?在第二个选项中,用户将点击主页,解析并缓存 DNS 主机,准备好在我的内容页面上下载.

What I mean is if I am using Google's CDN to get jQuery on every page in my site will adding the <link /> above any difference? Or will it only help if, say, I am not referencing the CDN on my homepage but am on all other pages? In this second option the user would hit the homepage, resolve and cache the DNS host ready for the download on my content pages.

我想如果我知道这个问题的答案,我会对问题 1 有更好的理解.我正在尝试使用 Firebug 和 Chrome 开发人员工具并查看网络和资源面板,但我没有看到显着差异.我能看到的唯一趋势是,如果有的话,当我使用 <link/> 时完成我的请求需要更长的时间!!

I suppose if I knew the answer to this I'd have a better understanding of issue 1. I'm trying to use Firebug and Chrome developer tools and watching the Net and Resources panels but I'm seeing no significant difference. The only trend I can see is that, if anything, it is taking longer to complete my request when I'm using the <link />!!

我已阅读有关 MDNChromium 博客(都是旧的!)但我还是没明白.

I have read the documentation on MDN and the Chromium Blog (both old!) but I'm still just not getting it.

任何帮助将不胜感激 - 谢谢!

Any help will be appreciated - thanks!

更新 - 22/01/2013

只是阅读了一些关于这个问题的更多信息,并认为我应该包括有同样问题的人的链接.csswizardry 写了一篇关于性能的很棒的文章,其中 他提到了这个问题 并链接到 来自 perfplanet 的更多研究.如果有人对此有更多信息/见解,请添加答案!

Just read some more around this issue and thought I should include the links for people with this same question. csswizardry has written a great article on performance in which he references this issue and links to more research from perfplanet. If anyone have more information / insight about this please add an answer!

这是另一个最近的问题的链接 - 希望是这个将帮助人们找到他们正在寻找的答案.

This is a link to another, more recent, SO question - hopefully this will help people find the answers they are looking for.

推荐答案

在第一种情况下,DNS 预取将无济于事,因为您在每个页面上加载相同的资源.该资源应在后续请求中缓存,因此预取 dns 记录不会有任何影响.

In the first case, DNS pre-fetching will not help as you are loading the same resource on each page. The resource should be cached on subsequent requests, so pre-fetching the dns record won't have any effect.

在第二种情况下,简单地删除和添加 link 元素不足以测试预取的效果.即使没有链接元素,浏览器也会扫描 href 以确定要预取哪些域 - 链接标签旨在告诉它除了浏览器会找到的域之外还预取一个域 - 这在您知道链接的情况下很有用到一个域最终会重定向到另一个域.

In the second case, simply removing and adding the link element is not sufficient to test the effect of prefetching. Even without the link element, the browser will scan hrefs to determine which domains to prefetch - the link tag is meant to tell it to prefetch a domain in addition to those the browser would find - this is useful in the case where you know a link to one domain is ultimately redirected to another.

查看预取标记效果的一种方法是设置几个站点.www.example.com/index.html 将包含指向 www.anotherexample.com 的链接,该链接又会重定向到 www.athirdsite.com.如果您在使用和不使用指向 www.athirdsite.com 的链接标签的情况下测试此配置,您可能会发现使用链接标签会更快.如果正在使用的名称服务器具有高延迟,您更有可能看到这种效果.

One way to see the effect of the prefetch tag would be to set up a few sites. www.example.com/index.html would contain a link to www.anotherexample.com which would, in turn, redirect to www.athirdsite.com. If you were to test this configuration with and without a link tag pointing to www.athirdsite.com, you may see that it is faster with the link tag. You are far more likely to see this effect if the nameserver in use has high latency.

最后,我只是让浏览器做它的事情,除非你有一个非常特别的理由指示它做其他事情.

In closing, I'd simply let the browser do its thing unless you have a very particular reason for instructing it to do something else in addition.

这篇关于dns 预取/预解析主机名 - 效果如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆