How do I encapsulate third-party JavaScript files so they don't pollute the global scope? -
one of clients asking if can add javascript track user behavior website. @ first glance fear going interfere other third-party analytics scripts on site because looks both parties have used same javascript compressor. don't want comb through , search every possible naming collision . . .
is there way can include third-party scripts (script files live on separate domain) wrap them in own namespace or give them own scope don't collide other globally declared variables , functions?
it should not problem. javascript compressors not rename global variables (for obvious reasons), , well-designed script not expose many (any) globals. if want deploy on page, responsibility prevent clashes.
Comments
Post a Comment