dns 预取/预解析主机名 - 效果如何?

发布于 2024-12-09 18:05:22 字数 1530 浏览 0 评论 0原文

我一直在阅读它是如何工作的,但正在努力理解它。

据我所知,如果我在网页的头部设置 应该 如果我引用此域上的任何资产,请求完成速度会更快。 [ref]

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

1)这是否唯一对未来页面请求的帮助

我的意思是,如果我使用 Google 的 CDN 在我网站的每个页面上获取 jQuery,将在任何差异上方添加 ?或者,只有当我不在主页上引用 CDN,而是在所有其他页面上引用 CDN 时,它才会有帮助吗?在第二个选项中,用户将访问主页,解析并缓存 DNS 主机,以供在我的内容页面上下载。

2)如何测试其有效性?

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

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

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

更新 - 22/01/2013

只需阅读有关此问题的更多内容,我认为我应该为有相同问题的人提供链接。 csswizardry 写了一篇关于性能的精彩文章,其中 他引用了此问题并链接到来自 perfplanet 的更多研究。如果有人对此有更多信息/见解,请添加答案!

这是另一个最近的问题的链接 - 希望这会对人们有所帮助找到他们正在寻找的答案。

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

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:

1) Does this only help for future page requests

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.

2) How can I test the effectiveness of this?

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 />!!

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!

UPDATE - 22/01/2013

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷鸟归林 2024-12-16 18:05:22

在第一种情况下,DNS 预取不会有帮助,因为您在每个页面上加载相同的资源。该资源应该在后续请求中缓存,因此预取 dns 记录不会产生任何效果。

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

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

最后,我只是让浏览器做它的事情,除非你有一个非常特殊的原因指示它做其他事情。

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.

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文