【发布时间】:2016-04-28 16:32:57
【问题描述】:
我必须单独预取子域吗?
例如当我有<link rel="dns-prefetch" href="//example.com"> 时,我还需要为//static.example.com 添加一个额外的标签吗?
【问题讨论】:
标签: html performance dns prefetch
我必须单独预取子域吗?
例如当我有<link rel="dns-prefetch" href="//example.com"> 时,我还需要为//static.example.com 添加一个额外的标签吗?
【问题讨论】:
标签: html performance dns prefetch
我做了以下测试:首先创建简单的 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,不提供顶级域。
【讨论】: