20

Do I have to prefetch a subdomain separately?

E.g. when I have <link rel="dns-prefetch" href="//example.com"> do I need an additional tag for //static.example.com as well?

damian
  • 5,314
  • 5
  • 34
  • 63

2 Answers2

34

I've made the following test: first created simple HTML page

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

For the domain and subdomain for which I own dns nameserver. Then I cleaned dns cache and opened this page in firefox private window. I observed in the logs of my dns nameserver that only request for "example.com" was made and no requests for subdomains.

Then I changed the page as follows:

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

Again cleared dns cache and opened this page in firefox private window. Now I observed that dns requests we made for both domain and it's subdomain.

So I can conclude that yes - you have to prefetch subdomains separately.

Volker E.
  • 5,911
  • 11
  • 47
  • 64
Evk
  • 98,527
  • 8
  • 141
  • 191
8

You have to prefetch every subdomain separately.

It is how DNS works. You ask for name, it answers back, it knows nothing about "subdomains" it's just a name.

nslookup google.com gives you answers for google.com only, no subdomains.

nslookup www.google.com gives www.google.com only, no top-level domains.

Darigaaz
  • 1,414
  • 10
  • 11
  • 5
    That is true but still dns-prefetch is a browser-related feature, and browser _could_ (in theory) inspect page and prefetch subdomains of some domain you set in dns-prefetch. Of course browsers don't do that, but still. – Evk May 08 '16 at 09:57