Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DNS prefetching and page optimization [duplicate]

Today I saw this snippet in the HTML source of a webpage:

<!-- prefetch dns -->
<link rel="dns-prefetch" href="//s3.amazonaws.com">
<link rel="dns-prefetch" href="//cdn.api.twitter.com">
<link rel="dns-prefetch" href="//graph.facebook.com">
<link rel="dns-prefetch" href="//connect.facebook.net">
<link rel="dns-prefetch" href="//api.pinterest.com">
<link rel="dns-prefetch" href="//google-analytics.com">

How much can you gain by doing this? I haven't seen this before, nor in the Yahoo! Developer Networks guidelines for optimization. The only thing that seems related is "Reduce DNS Lookups".

In a similar fashion, why doesn't these services expose an IP address to their services and avoid the DNS look-up altogether?

like image 347
Javier Constanzo Avatar asked Oct 13 '12 16:10

Javier Constanzo


People also ask

What is a DNS-prefetch?

DNS-prefetch is an attempt to resolve domain names before resources get requested. This could be a file loaded later or link target a user tries to follow.

What is the difference between preloading and prefetching resources?

Preload is an early fetch instruction to the browser to request a resource needed for a page (key scripts, Web Fonts, hero images). Prefetch serves a slightly different use case — a future navigation by the user (e.g between views or pages) where fetched resources and requests need to persist across navigations.


1 Answers

I guess that this gives parallel DNS lookup of those links later used for a bunch of JavaScript's.

Direct IP-numbers does not work well with CDN's. They resolve to a host close to the caller. If you are in the US they give you the IP of a server in US. If you are in Europe they give you the IP of a server in Europe, etc. You can't cheat like that with direct IP numbers.

like image 197
Albin Sunnanbo Avatar answered Oct 03 '22 18:10

Albin Sunnanbo