Speed Up Your CDN With DNS Prefetch

Posted by: 
Dejan Grofelnik Pelzel
Dejan Grofelnik Pelzel
May 14th, 2016

There's a neat little trick that allows you to squeeze an extra few milliseconds by pre-fetching your CDN hostnames in the HTML head section using a simple HTML5 tag. What this does is it tells the browser to start resolving the hostname immediately after the HTML is loaded. This means that when a file residing on the hostname is first requested there is no need to wait for the DNS lookup as it is most likely already resolved and waiting in the cache.

This can reduce the load time of your website anywhere from a few up to a few hundred milliseconds.

Best of all, DNS prefetching is incredibly easy to implement and is supported by most modern browsers. Just add the following link tag to your head section and replace the hostname with your own for each of the hostnames that you would like to prefetch.

<link rel="dns-prefetch" href="//cdn.mysite.com">

When you're looking to squeeze every little bit of performance possible, small things can really add up and this is just one of the tricks you can use to make your website load as fast as possible.