DNS预取子域名

dam*_*zzi 13 html dns performance prefetch

我是否必须单独预取子域?

例如,当我这样<link rel="dns-prefetch" href="//example.com">做时,我还需要一个额外的标签//static.example.com

Evk*_*Evk 19

我做了以下测试:首先创建了简单的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>
Run Code Online (Sandbox Code Playgroud)

对于我拥有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>
Run Code Online (Sandbox Code Playgroud)

再次清除dns缓存并在firefox私有窗口中打开此页面.现在我观察到dns请求我们为域和它的子域做了.

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


Dar*_*aaz 5

您必须单独预取每个子域.

这是DNS的工作方式.你问名字,它回答,它对"子域名"一无所知它只是一个名字.

nslookup google.com 只为google.com提供答案,没有子域名.

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

  • 这是真的,但仍然是dns-prefetch是一个与浏览器相关的功能,而浏览器_could_(理论上)检查页面并预取您在dns-prefetch中设置的某个域的子域.当然浏览器不会这样做,但仍然如此. (3认同)