大网数据广告活动
网站运营与故障问答

Should I dns-prefetch all Google Ads domains?

· 52CE 我爱测

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…

问题原文

原帖链接 · 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,

  1. 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).

  2. The analytics code (and therefore the DNS request) is in the document's head anyway, so there is no real time to be saved, unless your document's head is obscenely large and the analytics code is at the bottom

  3. Even 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

  4. 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-12-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。