Welcome to Geoffrey Swift's βlog. Please subscribe to the Atom feed.


Bypass JavaScript with Squid

I mentioned previously how I used the redirect_program feature in the Squid web proxy to filter out adverts from Channel 4's 4oD service. I did that by intercepting and modifying ASX files. In this article I explain how similarly one can deactivate unwanted JavaScript code.

One motivation for intercepting JavaScript is to avoid advertising, I'm also bypassing Google Analytics. For an entirely self contained JavaScript, your own blank script can be substituted. This works well for example with Google's advertising script show_ads.js.

To use Google Analytics, web site authors must write their own code to invoke the functions Google supply in their JavaScript files. So if Google's code is simply replaced by a blank file, JavaScript errors will result as required functions have not been defined. I've therefore written my own versions of their scripts which mimic the necessary code entry points, but don't actually do anything.

A replacement for the original Google file urchin.js was trivial:

function urchinTracker(){}

but the recently updated Google Analytics script ga.js was a bit more complicated:

var _gat = { _getTracker:function(s) { return { _initData:function(){}, _trackPageview:function(){} } } }

The scripts mentioned above are very popular on many websites. My replacement versions are obviously going to help speed up load times on several web pages, as the web browser has less work to do. Another bonus is that I avoid being included in my own Analytics data, and I get a better idea of who else is looking at my site!

Comments

Some sites have their own copy of the Google Analytics scripts, so intercepting the JavaScript file isn't always possible. Both scripts both work by downloading a web-bug (a 1 pixel by 1 pixel GIF). For completeness, I've added a rule to access my own (cached) image file instead. This speeds up web page access and improves anonymity further.

Comments for this post are now closed.