Web Surfing Speed Tip

Discussion in 'macOS' started by jmxp69, Dec 13, 2008.

  1. jmxp69 macrumors 6502

    Dec 10, 2008
    I've been using a file similar to this for several years. It works on any machine with a TCP stack and a hosts file. I can't take credit for creating the file, but for the life of me I can't re-locate the original website that put it together.

    Here's what it does:

    Many websites use external servers to serve any number of marketing, ad tracking, flash advertisements, cookie tracking, ad infinitum...

    The hosts file exists on your machine to provide local resolution of host names. For example, if you enter www.somesite.com in a network application (FTP, Safari, Transmission etc..), your machine will need the numeric address of the machine you're trying to connect to before making a connection. It does this by asking a nameserver for that IP address. It's actually a bit more complicated than that, but this is the general idea.

    Host files will provide local resolution of domain names in the format of:
    <ip address> <host>

    You also need to tell your machine to consult the hosts file before asking a nameserver for help.

    To do that, you edit /etc/resolv.conf as root and put the following line above the nameservers line:

    order hosts, bind

    See this thread for important info on OSX handling of resolv.conf:

    This tells your computer to look at the hosts file before asking a DNS (bind) server for help.

    Before you take the next step, copy your original /etc/hosts file to /etc/hosts.save That way, you can restore your machine to it's original state in case you botch something up or are unhappy with the results.

    Finally, edit your /etc/hosts file and paste in the contents from this page:

    Why does this make a difference?

    1) When you surf the web, your machine will connect not only to the primary website you entered, but also to any webserver referenced by the primary. Ads, cookies, movies, flash etc...etc... So for every page you load up, you might actually be connecting to 5 or 10 or 15 websites. If you can eliminate content requests from 5 or 10 or 15 different locations, the website you actually want to see will show up faster.

    2) This will make some pages look ugly. Once you put these entries in your hosts file, pages that have space set aside for this external content will display error messages like "content not found" because you broke the links to those external websites by using this host file. Not to worry though, the original content that you were actually interested in will still be there.

    3) The address is not routable and translates to "your machine". So if you type in your web browser, it will load up the web page served by your own machine if you're running a webserver. These host entries basically tell your network application that YOU are the webserver for all that content you really don't want to see. Of course, since your machine isn't serving that content, it will quickly reply with an error saying..."I don't have that content"

    4) This file isn't 100% foolproof, and it never will be because there are simply too many host names and servers out there dishing up the undesirable content. This is why the Internet uses bind (DNS) in the first place. Hosts files simply aren't scalable. This technique will eliminate a large portion of those extraneous connections though.

    5) If you ever want to go back to the way it was, just: cp /etc/hosts.save /etc/hosts (you did backup the original like I suggested right?)

    6) This tip impacts all applications that use IP addressing, not just the web browser, however; the primary impact will be on web browsing because generally, websites are the ones serving up the 'extra' content.

    My experience with this tweak is that web pages feel faster, Safari (firefox, opera, ie) all feel faster because they're not processing data that you didn't really want to see anyway.


  2. Keleko macrumors 68000

    Mar 26, 2008
    ...or you can install a plugin for ad blocking. Then you can turn it on/off from the browser if a page breaks because you blocked the ads.

    Look for Safari AdBlock and/or Adblock Plus for Firefox.
  3. martychang macrumors regular

    Sep 3, 2007
    Except not everyone uses Firefox, and Safari Adblock uses the lovely security blunder that is InputManagers. The old-fashioned UNIX way is the one that's technically correct.

Share This Page