Pre-Resolve DNS

Objective

Reduce DNS lookup time by pre-resolving at the browser.

Configuration

The 'Pre-Resolve DNS' filter is enabled by specifying:

Apache:
ModPagespeedEnableFilters insert_dns_prefetch
Nginx:
pagespeed EnableFilters insert_dns_prefetch;

in the configuration file.

Description

DNS resolution time varies from <1ms for locally cached results, to hundreds of milliseconds due to the cascading nature of DNS. This can contribute significantly towards total page load time. This filter reduces DNS lookup time by providing hints to the browser at the beginning of the HTML, which allows the browser to pre-resolve DNS for resources on the page.

Operation

This filter inserts the tag <link rel="dns-prefetch"> (or <link rel="prefetch"> for IE9) in the HEAD section, for all domains present in the HTML document.

Example

The example below shows the HTML before rewriting:

<html>
  <head>
  </head>
  <body>
    <img src="www.domain1.com/image1.jpeg">
    <script src="www.domain2.com/script1.js">
  </body>
</html>

and after rewriting:

<html>
  <head>
    <link rel="dns-prefetch" href="//www.domain1.com">
    <link rel="dns-prefetch" href="//www.domain2.com">
  </head>
  <body>
    <img src="www.domain1.com/image1.jpeg">
    <script src="www.domain2.com/script1.js">
  </body>
</html>

Limitations

This filter will be applied only on Firefox 3.5+, Chrome, Safari 5+ and IE 9+.

Risks

This filter is considered minimal risk.