I've been reading up on how this works but am struggling to make sense of it.
From what I can tell if I set <link rel="dns-prefetch" href="//ajax.googleapis.com" />
in the head of my webpage I should see a faster request completion is I reference any assets on this domain. [ref]
Now there are two issues which are currently bothering me:
What I mean is if I am using Google's CDN to get jQuery on every page in my site will adding the <link />
above any difference? Or will it only help if, say, I am not referencing the CDN on my homepage but am on all other pages? In this second option the user would hit the homepage, resolve and cache the DNS host ready for the download on my content pages.
I suppose if I knew the answer to this I'd have a better understanding of issue 1. I'm trying to use Firebug and Chrome developer tools and watching the Net and Resources panels but I'm seeing no significant difference. The only trend I can see is that, if anything, it is taking longer to complete my request when I'm using the <link />
!!
I have read the documentation on MDN and the Chromium Blog (both old!) but I'm still just not getting it.
Any help will be appreciated - thanks!
UPDATE - 22/01/2013
Just read some more around this issue and thought I should include the links for people with this same question. csswizardry has written a great article on performance in which he references this issue and links to more research from perfplanet. If anyone have more information / insight about this please add an answer!
This is a link to another, more recent, SO question - hopefully this will help people find the answers they are looking for.
A DNS prefetch is a resource hint to make a DNS lookup for a domain the browser has not yet determined needs to be made. This can improve performance because when the browser does need to make a request for a resource, the DNS lookup for that domain has already occurred.
dns-prefetch : indicates to the browser that it should perform the resolution of a given domain name (determining the IP to contact) before that domain is used to download resources. preconnect : indicates to the browser that it should connect a given origin, before that domain is used to download 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.
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.
In the first case, DNS pre-fetching will not help as you are loading the same resource on each page. The resource should be cached on subsequent requests, so pre-fetching the dns record won't have any effect.
In the second case, simply removing and adding the link
element is not sufficient to test the effect of prefetching. Even without the link element, the browser will scan hrefs to determine which domains to prefetch - the link tag is meant to tell it to prefetch a domain in addition to those the browser would find - this is useful in the case where you know a link to one domain is ultimately redirected to another.
One way to see the effect of the prefetch tag would be to set up a few sites. www.example.com/index.html would contain a link to www.anotherexample.com which would, in turn, redirect to www.athirdsite.com. If you were to test this configuration with and without a link tag pointing to www.athirdsite.com, you may see that it is faster with the link tag. You are far more likely to see this effect if the nameserver in use has high latency.
In closing, I'd simply let the browser do its thing unless you have a very particular reason for instructing it to do something else in addition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With