4

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" />
2
  • 2
    Ads are rendered after the page has loaded so this would make little to no difference. Dec 27 '18 at 20:18
  • Hi @SimonHayter I have a doubt. If in case someone uses preconnect (not dns-prefetch) on most common ads domains, wouldn't there be a performance improvement ?
    – Kannan
    Oct 5 '20 at 7:00
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.