jquery - How to Isolate Javascript on 3rd Party Sites? -


we've building small self-rendering javascript component embedded on many third party sites. our javascript depend on several common libraries (zepto, hogan, etc).

what's best way isolate our javascript polluting global namespace or interfering other javascript on third party site? there special error handling considerations/wrappers should use ensure our javascript doesn't prevent rendering?

the goal have single script embedded on third party site renders interactive content in dom, otherwise remains entirely isolated.

after reading more this, i'm going use closure based wrapper , jquery noconflict mode so:

(function(window, document, undefined){   // inject contents of jquery-2.0.3.min.js here   var $ = jquery.noconflict(true); //remove global jquery , alias locally    //define application classes , init here using local $ })(window, document); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -