Speed up your browsing with help from your hosts file
Web pages these days are so full of advertisements, trackers, counters, hidden pixels, it’s a wonder they load at all. And who knows what information you’re revealing about your browsing habits.
Browser plugins like Adblock Plus and Ghostery can filter out a lot of the crud, but because these are scripts run in the browser itself, they can’t always stop the content actually being downloaded – they just hide or disable it once it’s arrived. So your web page will speed up but not by as much as is actually possible.
A better way to stop a lot of this unwanted material before it even reaches your computer is to get your operating system to block it for you.
This is done by editing (or replacing) a specific file on your computer, called “hosts“.
When your computer is asked to find a URL, whether it’s a web page, an image, a counter, or anything else, it first checks its hosts file to see if there is a particular entry telling it where to look, before it then hits the internet in order to find the object.
So it follows that if you don’t want to receive any advertisement images from (say) “adverts-r-us.com”, then if you add an entry to your hosts file saying that adverts-r-us.com is actually on your own computer, not on the web, when you computer loads a web page containing an ad on that domain, it will immediately fail to find the ad, so your browser will receive an error (which you’ll never see) and you won’t receive the ads. And this all happens in milliseconds because your computer isn’t even touching the web. Neat.
Of course, there are thousands if not millions of domains that serve up advertisements, counters, trackers, etc, and it would take a lifetime to find all of them and add them to your hosts file, by which time new ones would have sprung up. You’d never manage to block everything that is slowing down your browsing experience.
Guess what: someone has done it for you. At the someonewhocares.org website, an enterprising guy called Dan Pollock has posted a hosts file containing about 12,000 entries relating to domains that either serve you ads or track you in some way. So if you install it on your computer, your browser will be downloading much less unwanted material. This file is updated regularly, by the way.
Installation on a Mac
- Go to http://someonewhocares.org/hosts/ and you’ll see the contents of Dan’s hosts file. Drag your mouse from the first ‘#’ under the page title, right down to the bottom of the page (there will be a lot of scrolling so it will take a minute) and then copy it with CMD-C.
- Open your favourite text editor (I like TextWrangler though TextEdit should be fine), start a new document, paste what you just copied into the document, and save it on your desktop as a file called “hosts” (not “hosts.txt” or “hosts.doc”, just “hosts”).
- Now you have to put your new hosts file in the right place so your Mac will find it and use it. Open a Finder window and browse to the “etc” folder. It’s in the root folder of your boot drive. You may have to enable showing hidden files in order to see it.
- In that folder you’ll see there is already a file called “hosts”. No problem, rename it to “hosts.old”. You Mac will probably ask you for your password before renaming it for you.
- Now drag your new hosts file from your desktop into this folder. Again, your Mac will probably insist you enter your password before allowing the move.
- As a final step I restarted my Mac, to be sure that it would start using the new hosts file. I’m honestly not sure if you need to do this.
- Get ready for faster (and more private) browsing, especially on commercial sites with busy layouts and lots of advertising and trackers.
I’d recommend revisiting Dan’s site every few months and repeating the process, so that you pick up new trackers and domains that have been added.
Installation on Windows or Linux
If you read the hosts file on Dan’s website, you’ll see that in the initial comments block (all the lines starting with ‘#’), he’s given instructions for other platforms including Linux and various versions of Windows.