We found a post recently talking about performance increases gained from using the HTML5 Boilerplate system. Whilst we’re sure the changes it made to stylesheets and Javascript files will have made some difference, the claim was backed up by some very questionable performance graphs.

Amongst other issues, it was clear from the graphs that a large part of their speed increase between the two tests was the lack of a DNS lookup in the second test. In this case, there seemed to be many changes made at the same time, which understandably makes proper benchmarking somewhat difficult. Even if that wasn’t the case though, there is a lot that can be done to stop DNS from interfering with your tests.

Where’s the Cache?

The problem with DNS is that it is cached in so many different places. There’s a browser cache, an operating system cache, the cache at your ISP and possibly a few up-stream from them as well. We also need to think about other internal systems such as caching proxies that may be setup on your local network.

Only some of these caches are under our control – namely the browser, the operating system and possible a proxy. Clearing these between each test may help a little, but what of the caches located up-stream that we have no control over?

Compensating for DNS

Every tool we’ve seen for measuring website speed separates the retrieval of files into several stages, one of which is the time taken to process the DNS query. It’s possible to subtract these values from the overall retrieval time but if you’re doing in-depth analysis of page load then there may be two, three or more domains being accessed. It soon becomes unmanageable to carry these calculations forward through dependencies and blocking.

Eliminating It Altogether

Enter our saviour in this situation – the “hosts” file. A hosts file exists as an override to the DNS system. It is a tab-separated list of domains names and corresponding IP addresses. When doing any sort of performance work, we can manipulate the hosts file so DNS lookups are not performed at all. Instead, information is retrieved from our local filesystem – a task that won’t vary by much more than a few microseconds between tests.

Unix, Linux and Mac system are pretty standard and keep the hosts file under /etc/hosts or /etc/HOSTS. Hosts files on Windows vary depending on the version being run.

DNS Speed

Of course, this is not to say that you shouldn’t test your DNS speed as well. Many companies never move their domains away from the budget registrars they started with, so DNS can be a big contributor to slow-loading sites. Just try to test one thing at a time.