【问题标题】:DNS prefetching of subdomains子域的 DNS 预取
【发布时间】:2016-04-28 16:32:57
【问题描述】:

我必须单独预取子域吗?

例如当我有<link rel="dns-prefetch" href="//example.com"> 时,我还需要为//static.example.com 添加一个额外的标签吗?

【问题讨论】:

    标签: html performance dns prefetch


    【解决方案1】:

    我做了以下测试:首先创建简单的 HTML 页面

    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="dns-prefetch" href="//example.com/">     
      </head>
      <body>
        <a href="http://example.com">Test link</a>
        <a href="http://sub.example.com">Test link 2</a>
      </body>
    </html>
    

    对于我拥有 dns 名称服务器的域和子域。然后我清理了 dns 缓存并在 Firefox 私人窗口中打开了这个页面。我在我的 dns 域名服务器的日志中观察到,只请求了“example.com”,没有请求子域。

    然后我把页面改成如下:

    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="dns-prefetch" href="//example.com/">     
        <link rel="dns-prefetch" href="//sub.example.com/">
      </head>
      <body>
        <a href="http://example.com">Test link</a>
        <a href="http://sub.example.com">Test link 2</a>
      </body>
    </html>
    

    再次清除 dns 缓存并在 firefox 私人窗口中打开此页面。现在我观察到我们为域及其子域发出的 dns 请求。

    所以我可以得出结论,是的 - 您必须单独预取子域。

    【讨论】:

    • 感谢您的回答!
    【解决方案2】:

    您必须分别预取每个子域。

    这就是 DNS 的工作方式。您询问名称,它会回复,它对“子域”一无所知,它只是一个名称。

    nslookup google.com 只为您提供 google.com 的答案,不提供子域。

    nslookup www.google.com 仅提供 www.google.com,不提供顶级域。

    【讨论】:

    • 确实如此,但 dns-prefetch 仍然是与浏览器相关的功能,浏览器可以(理论上)检查页面并预取您在 dns- 中设置的某些域的子域预取。当然浏览器不会这样做,但仍然如此。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 2019-08-09
    • 2019-02-11
    • 2017-09-16
    • 2013-07-22
    • 2015-06-29
    相关资源
    最近更新 更多