Why Amazon.com Pages Rely on DNS Pre-fetch

The article presents a perspective on why Amazon.com pages rely on DNS pre-fetch and what other e-commerce websites could learn from this.

 

Whats Happening Under the Hood?
As you do the view source of the homepage, amazon.com, you would find following Javascript code snippet, right at the top of the page:

 

<meta http-equiv=”x-dns-prefetch-control” content=”on”>
<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”>

 

Later, in the same page as well as other pages, you would find several resources such as images, Javascript, CSS files accessed from one of the above as base URLs. So, let’s try and explore some of the benefits from this approach.

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:

  • g-ecx.images-amazon.com
  • z-ecx.images-amazon.com
  • ecx.images-amazon.com
  • completion.amazon.com
  • fls-na.amazon.com

 

Key Observations (Best Practices)
  1. 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.
  2. 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.
  3. Note the usage of meta tag to control the dns-prefetch to “on” or “off”.

 

 

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking. Check out my other blog, Revive-n-Thrive.com

View Comments

  • Hi there! Quick question that's completely off topic.
    Do you know how to make your site mobile friendly?
    My website looks weird when viewing from my apple iphone.
    I'm trying to find a theme or plugin that might be able to
    resolve this issue. If you have any suggestions, please share.
    Appreciate it!

Share
Published by
Ajitesh Kumar

Recent Posts

Mean Squared Error vs Cross Entropy Loss Function

Last updated: 28th April, 2024 As a data scientist, understanding the nuances of various cost…

2 days ago

Cross Entropy Loss Explained with Python Examples

Last updated: 28th April, 2024 In this post, you will learn the concepts related to…

2 days ago

Logistic Regression in Machine Learning: Python Example

Last updated: 26th April, 2024 In this blog post, we will discuss the logistic regression…

4 days ago

MSE vs RMSE vs MAE vs MAPE vs R-Squared: When to Use?

Last updated: 22nd April, 2024 As data scientists, we navigate a sea of metrics to…

5 days ago

Gradient Descent in Machine Learning: Python Examples

Last updated: 22nd April, 2024 This post will teach you about the gradient descent algorithm…

1 week ago

Loss Function vs Cost Function vs Objective Function: Examples

Last updated: 19th April, 2024 Among the terminologies used in training machine learning models, the…

2 weeks ago