Troubleshooting Slow Page Loads in Safari

Disabling DNS prefetching can improve Safari's performance

Rocket graphic coming out of laptop
Atomic Imagery | Getty Images

Safari, along with just about every other browser, now includes DNS prefetching, a feature designed to make surfing the web a speedier experience by looking at all of the links embedded in a web page and querying your DNS server to resolve each link to its actual IP address.

When DNS prefetching is working well, by the time you select a link on a website, your browser already knows the IP address and is ready to load the requested page. This means very fast response times as you move from page to page.

So, how can this be a bad thing? Well, it turns out that DNS prefetching can have some interesting drawbacks, although only under specific conditions. While most browsers now have DNS prefetching, ​we're going to concentrate on Safari, since it's the leading browser for the Mac.

When Safari loads a website, sometimes the page is rendered and appears ready for you to peruse its content. But when you try to scroll up or down the page or move the mouse pointer, you get a spinning cursor. You may notice that the browser refresh icon is still spinning as well. All of this indicates that while the page has been successfully rendered, something is preventing the browser from responding to your needs.

There are a number of possible culprits. The page could have errors, the site server may be slow, or an off-site part of the page, such as a third-party ad service, might be down. These types of issues are usually temporary, and will probably go away in a short time, from a few minutes to a few days.

DNS prefetching issues work a little differently. They usually affect the same website whenever you visit it for the first time in a Safari browser session. You might visit the site in the early morning and find that it's extremely slow to respond. Come back an hour later, and all is well. The next day, the same pattern repeats itself. Your first visit is slow, really slow; any subsequent visits that day are just fine.

What's Going on With DNS Prefetching?

In our example above, when you go to the website first thing in the morning, Safari takes the opportunity to send out DNS queries for every link it sees on the page. Depending on the page you're loading, it could be a few queries or it could be thousands, especially if it's a website that has lots of user comments or you're visiting a forum of some type.

The problem isn't so much that Safari is sending out tons of DNS queries, but that some older home network routers can't handle the request load, or that your ISP's DNS system is undersized for requests or a combination of both.

There are two easy methods of troubleshooting and resolving DNS prefetching performance issues. We're going to take you through both methods.

Change Your DNS Service Provider

The first method is to change your DNS service provider. Many people use whatever DNS settings their ISP tells them to use, but in general, you can use any DNS service provider you want. In our experience, our local ISP's DNS service is pretty bad. Changing service providers was a good move on our part; it may be a good move for you as well.

You can test your current DNS provider using the instructions in an online guide.

If after checking your DNS service you decide to change to a different one, the obvious question is, which one? You can try OpenDNS or Google Public DNS, two popular and free DNS service providers, but if you don't mind doing a little tweaking, you can use a guide to test various DNS service providers to see which one is best for you.

Once you have picked a DNS provider to use, you can change your Mac's DNS settings.

Once you have changed to another DNS provider, quit Safari. Relaunch Safari and then try the website that was causing you repeated problems.

If the site is loading OK now, and Safari remains responsive, then you're all set; the problem was with the DNS provider. To make doubly sure, try loading the same website again after you shut down and restart your Mac. If everything still works, you're done.

If not, the problem is probably elsewhere. You can revert to your earlier DNS settings, or just leave the new ones in place, especially if you changed to one of the DNS providers we suggested above; both work very well.

Disable Safari's DNS Prefetch

If you are still having problems, you can solve them by never visiting that website again, or by disabling DNS prefetching.

It would be nice if DNS prefetching was a preference setting in Safari. It would be even nicer if you could disable prefetching on a site-by-site basis. But since neither of these options is currently available, we'll have to use a different approach to disable the feature.

  1. Launch Terminal, located at /Applications/Utilities.

  2. In the Terminal window that opens, enter or copy/paste the following command:

    defaults write com.apple.safari WebKitDNSPrefetchingEnabled -boolean false
    
  3. Press Enter or Return.

  4. You can then quit Terminal.

Quit and relaunch Safari, and then revisit the website that was causing you problems. It should work fine now. The problem was likely an older router in your home's network. If you replace the router someday, or if the router manufacturer offers a firmware upgrade that resolves the issue, you will want to turn DNS prefetching back on. Here's how.

  1. Launch Terminal.

  2. In the Terminal window, enter the following command:

    defaults write com.apple.safari WebKitDNSPrefetchingEnabled
    
  3. Press Enter or Return.

  4. You can then quit Terminal.

That's it; you should be all set. In the long run, you're usually better off with DNS prefetching enabled. But if you frequently visit a website that has issues, turning DNS prefetching off can make the daily visit a more enjoyable one.

Was this page helpful?