问题原文
原帖链接 · Toto · CC BY-SA 4.0
On our website, we dns-prefetch our domains (static files, subdomains, etc) as they may not be known.
1) Does it make sense to dns-prefetch Google Ads or Analytics domains as they are popular?
2) If yes, as Google Ads love to use lots of domains, should we include all of them?
<link href="//adservice.google.ch" rel="dns-prefetch" />
<link href="//adservice.google.com" rel="dns-prefetch" />
<link href="//cm.g.doubleclick.net" rel="dns-prefetch" />
<link href="//csi.gstatic.com" rel="dns-prefetch" />
<link href="//encrypted-tbn0.gstatic.com" rel="dns-prefetch" />
<link href="//encrypted-tbn1.gstatic.com" rel="dns-prefetch" />
<link href="//encrypted-tbn2.gstatic.com" rel="dns-prefetch" />
<link href="//encrypted-tbn3.gstatic.com" rel="dns-prefetch" />
<link href="//fonts.googleapis.com" rel="dns-prefetch" />
<link href="//googleads.g.doubleclick.net" rel="dns-prefetch" />
<link href="//image6.pubmatic.com" rel="dns-prefetch" />
<link href="//pagead2.googlesyndication.com" rel="dns-prefetch" />
<link href="//tpc.googlesyndication.com" rel="dns-prefetch" />
<link href="//www.google.com" rel="dns-prefetch" />
<link href="//www.googletagservices.com" rel="dns-prefetch" />
社区高分解答
原帖链接 · Maximillian Laumeister · CC BY-SA 4.0
I wouldn't bother preloading DNS for Google Analytics or ads. As Simon mentioned, ads are generally loaded with lower priority than the rest of the content anyway, so it's not like they would be holding up the rendering of the rest of your page.
With Google Analytics in particular,
The script is loaded asynchronously, which means that it does not slow the loading of any of the rest of your page (in a practical sense).
The analytics code (and therefore the DNS request) is in the document's
headanyway, so there is no real time to be saved, unless your document'sheadis obscenely large and the analytics code is at the bottomEven if there were time to be saved, it would only be on the visitor's first page visit as the DNS will get cached, and
Since Google Analytics is so prevalent, it is quite likely that the visitor has not only preloaded the DNS for the tracking domain, but they might even have the entire script loaded in their browser cache already, despite
analytics.js's short 2-hour caching time.
If you want to leverage preloading, I would recommend keeping it to resources that both the user is likely not to have dns-cached in their browser already, and which block rendering on your web page.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
