3

Using a CDN can vastly improve the load time of a website. I been thinking of using it to host all my external files like CSS, JS, Images, Videos etc. However I was thinking when linking to a CDN, wouldn't the browser have to use additional DNS lookup? So wouldn't this be counter productive? Or is the benefit to host every external files on a CDN out weighs the additional cost of a DNS lookup?

What are your thoughts?

3 Answers 3

3

You could try both and use a service like http://www.webpagetest.org to see which option works best.

0
2

Yes, a DNS lookup will have to take place, however, as with most things these days; they have the possibility of being cached either by the OS, or by the browser itself.

You'll find that servers used for DNS resolution are normally much closer both topologically and geographically to the user than your server; meaning a smaller round-trip time than normal (DNS servers are normally located within the network of a user's ISP). A DNS lookup is also much smaller than the downloading of a web resource.

With this in mind, it'd be unlikely for such a small hit to outweigh such a potentially large gain (the fast download of all your assets). All in all, you should find that using a CDN will give you an advantage.

1

Actually the DNS lookup will be only ONE!

Once the OS looked up the domain DNS it will store the IP of the domain in its internal DNS table, and call directly the IP for all subsequent requests.

On Windows you can view the DNS table running the command: ipconfig /displaydns

Basically if in your site thare are 100 images + js + css and they are all on a CDN at some-cdn-domain.com, the browser will do only 1 DNS lookup, and not 100.

Therefor 1 DNS lookup will always be a no issue in term of speed. It could be if on the CDN you had only one file, but I struggle to see how a website can have only one static file nowadays.

4
  • Agreed, but in many cases, webmasters will create an alias to the CDN, which leads to 2 DNS resolve points.
    – Fer
    Apr 4, 2012 at 9:36
  • @Ferdy: alias on CDNs aren't usually just a different paths?! But different paths on the same CDN domain, therefor the DNS lookup should be only one, one per domain and NOT one per path. Apr 4, 2012 at 21:34
  • What is mean is this, often webmasters will create a clean alias in their own domain: static.yourdomain to com which will point to subdomain.cdn.com. That's two DNS points.
    – Fer
    Apr 5, 2012 at 6:52
  • @Ferdy: well if you create a subdomain you will definitely have 1 more DNS lookup, but still you will have a total of 2 DNS lookups (one the main domain and one for the subdomain), and not 100 DNS lookups (one for each image) unless you think to create a subdomain for each image on your web site. In such a case I would be worried it could be called overoptimization. Apr 5, 2012 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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