Html 子域的DNS预取

Html 子域的DNS预取,html,performance,dns,prefetch,Html,Performance,Dns,Prefetch,我必须单独预取子域吗 例如,当我有时,我是否也需要为//static.example.com添加一个标记?我做了以下测试:第一个创建的简单HTML页面 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="dns-prefetch" href="//example.com/"> <

我必须单独预取子域吗


例如,当我有
时,我是否也需要为
//static.example.com
添加一个标记?

我做了以下测试:第一个创建的简单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请求


所以我可以得出结论:是的,你必须分别预取子域。

你必须分别预取每个子域

这就是DNS的工作原理。你们问名字,它回答,它对“子域”一无所知,它只是一个名字

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


nslookup www.google.com
只提供www.google.com,没有顶级域名。

没错,但dns预取仍然是一项与浏览器相关的功能,浏览器(理论上)可以检查页面并预取在dns预取中设置的某个域的子域。当然,浏览器不会这样做,但仍然如此。谢谢你的回答!