"J. P. Gilliver (John)" wrote:
> I have some sites (including facebook and twitter) blocked in my hosts
> file.
>
> Some web pages have long pauses, with "waiting for" (or something
> similar - might be "waiting for response from") one of the blocked sites
> showing in the status line.
>
> Why is this? I thought putting something in the hosts file redirected
> things to the local computer, so there should be no delay. So presumably
> they're looking for some sort of script reply, or something?
>
> Any suggestions how to avoid these delays? (At worst, I presume I'd have
> to set up a web server on my machine?)
Don't use 127.0.0.1. That is localhost. Your host will actually try to
connect to a listening port on that host. That means timing out. It
should happen quickly but there is overhead. The idea was to point to
somewhere that no one was listening. I don't know why localhost became
the favorite. A better choice is 127.0.0.0. Can't have a server
listening on that port, no timeout waiting for a listening process that
isn't there. Your client won't even bother trying to connect to
127.0.0.0. I actually timed this and found 127.0.0.0 gives a faster
timeout than 127.0.0.1.
Of course, if you're using someone else's pre-compiled 'hosts' file,
like the one from MVPS, your choice is to leave all their entries
pointing at 127.0.0.1 and have your host timeout trying to make a
connection that won't happen or use an editor to change all 127.0.0.1 to
127.0.0.0 -- except you still need the "127.0.0.1 localhost" entry (so
change all and then change this one back). Plus later if you ever want
to run your own web server on your host then all those 127.0.0.1 entries
in the 'hosts' file would be connecting to your local web server.
127.0.0.1 represent the local host. It is your host. The 'hosts' file
was intended to point at hosts, not networks. 127.0.0.0 represents a
network, not a host, but it can still be used in the 'hosts' file. You
cannot connect to a network. You can only connect to a host. Your
client will instantly fail if the local DNS lookup via 'hosts' returns
127.0.0.0 because it cannot connect to a network versus your client
having to timeout at your local host's NIC interface to see there is no
process listing there.
When I specify 127.0.0.x where x = 1 to 254 (so the IP address is for a
host), it takes longer for the web browser to abort the connection
attempt. You see "Waiting for 127.0.0.x" or some other "hunt & connect"
status (which appears more than long enough to read it). Yet if
127.0.0.0 is used (for the network), the web browser fails instantly.
Since a web page could have dozens, or more, links to 3rd
party content that I am trying to nullify, it would seem faster rejects
(literally not trying at all to make the connects) would result in a
faster complete time to load (and render) the web page minus all the
blocked content.
Try it yourself. Have your web browser go to "
http://127.0.0.1", notice
it status message, and how long before it errors. Then try to connect
to "
http://127.0.0.0" and notice the web browser IMMEDIATELY fails.
Well, if it's faster on just one blocked local DNS lookup, imagine how
much faster a page would load if you did the same 127.0.0.0 return on
the dozens if not hundreds of off-domain links in a web page or scripts.
Personally I don't bother with using a 'hosts' file to block unwanted
content. The MVPS 'hosts' file, for example, is something like 20K
entries and searches through that file require an OPEN, READ, and CLOSE
operations and the search is linear from top to bottom (it is a file,
not a database). The size of these pre-compiled 'hosts' file have long
exceeded the recommended max of 8K entries after which the lookup could
take longer than the round-trip traffic for a DNS server request. The
list is of hosts and that means all those hosts at a domain. Just look
at how many are listed for
doubleclick.com. You cannot use 'hosts' to
redirect a domain to localhost. You have to specify hostnames in there.
Plus no one that uses these pre-compiled lists ever reviews them to
verify that they they agree with the author(s) that compiled these
lists. There is no quick and easy means of disabling the client from
using the 'hosts' file. It's not like there's a toolbar button to
toggle your web browser from using and not using the 'hosts' file. You
may visit a site that doesn't render properly but it would if you had a
blank 'hosts' file (just the "127.0.0.1 localhost" entry). 'hosts' is a
rather clumsy means of blocking unwanted content.
By the way, there are many sites that don't merely have links to the
social sites. They actually run scripts to gather statistics for those
sites. That is, they're in league with them to aggregate stats on their
visitors and how many visit the social sites for which they provide nav
routes. Those scripts might be on- or off-domain of the site you visit
but they are still running. You might want to look at add-ons that
disable scripts (e.g., NoScript) and you pick which ones are allowed to
run at a site, or an add-on that disables the hosted social site scripts
(I think Ghostery is one where you just pick some options to block
hosted social site scripts but there may be other add-ons to do the same
thing). Just visiting a site will run those hosted social site scripts
so they know you visited the first site. They're gathering stats on
your visits. You don't even have to click on the Like or Tweet buttons
you see at some site you happen to visit for them to know you were
there.
You may find sites are more speedy when you disable their scripts. Too
many sites require scripts to work so I configure NoScript to temporary
allow scripts at the 2nd level domain (domain.tld) for sites that I
choose to visit. Off-domain scripts won't run unless I either
temporarily allow them or whitelist them. For example, many sites use
JQuery that is hosted at Google's Code site. Not running the hosted
scripts for the social sites on the sites that you visit may eliminate
those delays you've been experiencing.
Another choice is to use Adblock Plus, and add-on for Firefox. That
will disable the URLs in scripts hosted on the site you visit that
report to the social sites.
http://googleplus.wonderhowto.com/how-to/prevent-social-networks-from-tracking-your-internet-activities-0130280/
I have Adblock Plus (besides NoScript) and subscribe it to the
EasyPrivacy+EasyList and Malware Domains lists (plus I have a few of my
own blocking filters). It's up to you to decide if Adblock's policy on
defaulting to allows some ad sites to work matches with your goals.
Many sites wouldn't be around if it weren't for ad revenue. They have a
list of rules to which an ad source must comply to be polite in
presenting their content in a web page. If you're against all ads and
refuse to even help those providing a web site out of their own pockets
to give you information then disable the "Allow some non-intrusive
advertising". You can read about this policy and ABP deems
non-intrusive by reading
https://adblockplus.org/en/acceptable-ads.
Note that using Adblock will significantly increase the memory footprint
for Firefox along with slowing the load of Firefox. Where Firefox
might've loaded and be ready in under 2 seconds will take 6 seconds with
ABP enabled. The longer the blocklists the larger the firefox.exe
process will be. When I used ABP with only my short list of blocked
domains, Firefox loaded faster and consumed much less memory. When I
add the blocklists, and with each one that is subscribed, Firefox takes
longer to load and eats more memory. So you'll have to decide if the
longer start time and increased memory usage is a sacrifice that is
outweighed by the time saved to render the web sites you visit within
one session of Firefox. At least with ABP, however, you can easily
disable it to get a page working whereas with a 'hosts' file you'll have
to unload the web browser, rename or delete the 'hosts' file, reload the
web browser, and then revisit the web page to see if it now works
without all the blocks.