2016-04-28 93 views
8

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

E.g.当我有<link rel="dns-prefetch" href="//example.com">时,我是否还需要//static.example.com的附加标签?

回答

10

我做了如下测试:首先创建简单的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要求我们为域和它的子域。

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

+0

感谢您的回答! – enyce12

5

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

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

nslookup google.com只为您提供google.com的解答,没有子域名。

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

+2

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