One of my clients is asking if they can add some JavaScript to track user behavior to their website. At first glance I fear that it is going to interfere with other third-party analytics scripts on the site because it looks like both parties have used the same JavaScript compressor. I don’t want to comb through and search for every possible naming collision so . . .
Is there a way I can include third-party scripts (script files which live on a separate domain) but wrap them in their own namespace or give them their own scope so they don’t collide with other globally declared variables and functions?
It should not be a problem. Javascript compressors do not rename global variables (for obvious reasons), and any well-designed script will not expose many (any) globals. If they want you to deploy it on your page, it is their responsibility to prevent clashes.