This week I got an angry tweet from @peter_lind. He was complaining about the use of global variables in almost every tracking script. I would say ad-scripts are just as bad. If not worse. I mean take a look at this little bastard:
As you might have figured out I’ve taken this from unt.se. The Ad-company is a common one used on a lot of big sites. People complained about them already back in 2010. Just look at this blog-post by Rob.
Let me tell you a story. A little bit over a year ago I was working on a site where they insisted on using AddThis. I really don’t like this sort of scripts but I guess I save that rant for another post. On the site I was also doing a component using Raphaël. All good. Or so I thought. But if I downloaded the minified version on Raphaël and put it together with AddThis I got a conflict. They were both using global variables! Bummer… Since then both of them have updated their scripts. Maybe/Hopefully cause people like me emailed them and complained.
But why are big companies still using global variables? Only explanation I can think of is that they think, just like Google Analytics (with global variable _gaq) that they are big enough to “own” a global variable. Cause they can’t be so bad that they don’t know how to do it better, no?
So please people producing js for the public: Do not pollute the global namespace! And no, do not think that if you are big enough it’s ok. You will never be that big.