Zap Annoyances on the Web, Part I

by Frank Merenda

Surfing the Web is something most of us do daily. At home I am on a dial-up connection, and I'm constantly looking for ways to make my browsing experience more efficient and to protect my privacy while on-line. The approach I describe here allows you to stop many ads, images, Web bugs and pop-up windows. In case you are not familiar with Web bugs, they are small graphics included on a Web site or in an e-mail that are used to track who is reading. Whether you are on a dial-up connection or a high-speed connection, the tools presented in this article are guaranteed to make your on-line browsing experience more enjoyable and to protect your personal habits from nosy marketers.

My environment consists of an IBM A31 ThinkPad with a 1.9GHz Pentium 4 Mobile CPU and 1GB of RAM running Fedora Core 1 (fedora.redhat.com). I am using Mozilla 1.5 (www.mozilla.org) as my Web browser.

The Approach

The approach we take here consists of the following three basic parts: Mozilla's image, JavaScript and pop-up window management capabilities; a proxy server to cache Web content; and a program to intercept requests for undesired content.

If you are not familiar with proxy servers, here's a quick overview. For the purpose of this article, we define a proxy server as an intermediate server used to intercept requests for Web pages and associated files. The proxy server either handles the request itself or passes the request on to another proxy server or to the original target. A proxy server can be transparent, intercepting all requests automatically. In our example we manually configure the browser to go through our proxy server. Proxy servers also can be used to proxy other types of requests, but that falls outside the scope of this article.

We are using Squid (www.squid-cache.org) as our proxy server. Squid is an extremely popular proxy server that's in use all over the world. Squid allows you to cache Web content locally, so instead of going out to the Internet for content you have previously downloaded, you can retrieve it from Squid's local cache. Squid is smart enough to know if content can be read from cache or if it must be updated from the originating Web site. If you are looking at a news site, for example, Squid knows that it needs to refresh the text on the site, but it usually loads the static images on the site from cache. Squid also gives us the ability to add in something called redirects, which intercept requests and possibly modify them in some way. For example, if you request an image that is known to be an advertisement, the intercept may return a placeholder image instead of the image requested, completely bypassing the request for the original image.

Implementing Our Solution

The first step is to set up Mozilla to block pop-up windows. The option to enable this feature can be found under Edit→Preferences→Privacy & Security→Popup Windows. You are greeted by the screen shown in Figure 1. Choosing the option to Block unrequested pop-up windows does exactly that. You can play a sound or display an icon when pop-ups are blocked if you so desire. There also is an option to allow pop-ups explicitly from certain sites. If you click on the button labeled Allowed Sites..., you are shown the screen in Figure 2. This feature is handy for sites that pop up external windows for things like showing progress for a long-running task. You can leave this list blank to start and add sites as you go.

Zap Annoyances on the Web, Part I

Figure 1. Block unrequested pop-up windows from Mozilla.

Zap Annoyances on the Web, Part I

Figure 2. You can permit pop-ups from sites that use them for legitimate purposes.

The second step is to configure Mozilla to manage JavaScript events. These settings can be found under Edit→Preferences→Advanced→Scripts & Plugins. Check boxes on this screen allow you to turn off JavaScript completely for your browser, mail and news readers. You also can keep JavaScript enabled and configure Mozilla to stop scripts from moving or resizing windows, raising or lowering windows, hiding or changing the statusbar, changing images, creating or changing cookies and reading cookies. The settings I use can be seen in Figure 3 and should work well for most situations.

Zap Annoyances on the Web, Part I

Figure 3. Disable the JavaScript features that Webmasters use to create annoyances.

The next step is to tackle setting up our Squid proxy server. If you have never set up a proxy server before, have no fear; setting up Squid is much easier than you think. First, check to see if you have Squid already installed on your system. This can be done by typing which squid. If you get back a path to Squid you're all set. If not, you can download prebuilt RPMs from rpmfind.net/linux/rpm2html/search.php?query=squid&submit=Search+..., or download the source from www.squid-cache.org. You also need Perl installed, which is pretty much guaranteed to be on your system already. Installing from source is easy; follow the three-step install instructions in the INSTALL file included with the source distribution:

% ./configure --prefix=/usr/local/squid
% make all
% make install

The latest version of Squid, at the time of this writing, is 2.5.STABLE4. I am using version 2.5.STABLE3, which shipped with Fedora Core 1.

Next, we configure Squid. Before updating your Squid configuration, we issue the stop command, /etc/init.d/squid stop, to make sure Squid is not running.

Now, edit the /etc/squid/squid.conf file as root. We are going to change only one setting in the default squid.conf file. Locate the line that reads:

# http_port 3128

and change it to:

http_port 8080 

This line changes the port on which Squid is running from the default port of 3128 to the easy-to-remember port of 8080. Although this step is not necessary, you probably want to do it so you can remember on which port Squid is running without having to look at the squid.conf file in the future. Keep in mind, though, that port 8080 may conflict with some applications, such as Tomcat or JBoss. If there is a port conflict, you can choose a different port for Squid. Now it's time to test our Squid configuration. Type the following command as root to start up Squid: /etc/init.d/squid start. You should see an OK after Squid starts. If you get an error, go back and check your configuration settings to identify the problem.

Now we're going to set up Mozilla to use Squid as a proxy server. To do this, go to Edit→Preferences→Advanced→Proxies. Choose the Manual proxy configuration and put in 127.0.0.1 for your HTTP Proxy and 8080 as the port. If you are running Squid on a port other than 8080, enter that value here. Put in the same values for your SSL Proxy. You should end up with something similar to what is shown in Figure 4.

Click OK and try to browse any Web site to make sure that Squid is functioning properly. A good test for this is to go to images.google.com and search on the term penguin. After the page loads up, click refresh in your browser and notice how much more quickly the images load the second time. The increased speed is from a combination of Mozilla's own built-in caching capabilities and Squid's caching of the images for you. As a test, I turned off Mozilla's built-in caching functionality and loaded up the penguin images page. The initial loading of the page took 27 seconds on my dial-up connection, while the second viewing took only a little over two seconds.

Zap Annoyances on the Web, Part I

Figure 4. Configure your browser to use the proxy server.

Part II of this articles explains how to use AdZapper to block many ads and Web bugs.

Frank Merenda is a systems architect for John Deere, where he writes J2EE applications on Linux, as well as a coauthor of the Linux site, uptime (uptime.steidler.net). He and his wife Jacq live with their seven dogs and five cats in rural Jackson County, Georgia, where they both are helping the Humane Society of Jackson County (www.hsjc.com) build an animal shelter. He can be reached at linux@frankandjacq.com.

Load Disqus comments

Firstwave Cloud