<link rel=”dns-prefetch” href=”http://g-ecx.images-amazon.com”>
<link rel=”dns-prefetch” href=”http://z-ecx.images-amazon.com”>
<link rel=”dns-prefetch” href=”http://ecx.images-amazon.com”>
<link rel=”dns-prefetch” href=”http://completion.amazon.com”>
<link rel=”dns-prefetch” href=”http://fls-na.amazon.com”>
DNS-prefetch technique attempts to resolve domain names using one’s computer’s built-in DNS resolution mechanism. Once a domain name gets resolved, further attempts to access any resources from that domain takes no time for DNS resolution. Thus, this does speed up the overall page loading time due to no time taken for DNS resolution. The reason why Amazon.com pages rely on DNS-prefetch is multiple domain names (as mentioned above) from which different web page resources such as images/JS/CSS are accessed. When the browser encounters these URLs, it first checks its cache and then, lacking a cached copy, resolves the domain to the associated IP address through a request from the DNS server. These requests happen in the background so as to not block the rendering of the page. Moreover, since all this takes place in parallel with the user’s reading of the page, it places only a negligible load on CPU and network resources.Although, browser does the activity of prefetch the URL, one forces the domain name pre-resolve by making use of attribute rel=”dns-prefetch” with link element. In above example, browser pre-resolves following domain name:
Key Observations (Best Practices)
- Interestingly, the above dns-prefetch links were found only on homepage and not on any other pages. The reason being the fact that it is considered as a best practice to use forced prefetching on the homepage of a site (as rightly done by Amazon.com) for different domain names that are referenced on other pages of the website. This helps improve overall performance of the website.
- The dns-prefetch links were found right on the top of the page. This is another best practice where browser comes to know about prefetch URLs as early as possible even before the actual page starts loading along with static web resources.
- Note the usage of meta tag to control the dns-prefetch to “on” or “off”.