NPM module that allows you to get multiple jQuery instances that are "detached" from the global namespace (
i.e. different versions of jQuery and/or multiple instances of the same version.
TODO Rename package to "jquery-detached" once we figure out of this is going to work. Do a global s&r
npm install --save detached-jquery-<jquery-version>
Of course, the above will depend on whether or not we have published that exact version of jquery. The easiest way to see the versions we have published is to look at the branch names on GutHub
Having run into issues using a single shared jQuery instance across multiple libraries/apps running a browser, each requiring different versions of jQuery, or unwittingly polluting the shared jQuery instance with extensions that conflict with each other.
Getting a shared jQuery instance
Creating multiple instances of jQuery should be avoided if possible, but only when that shared instance is not being polluted. When running in an environments where it is known to be safe to use a shared jQuery instance e.g. a closed environment, where everything is controlled (extensions etc), or in an environment where this shared instance is not modified through extension.
var jQuery = ;var $ = jQuery;var myDivs = ;// etc...
Getting a "new" jQuery instance
var jQuery = ;var $ = jQuery;//// Do something with your jQuery/$ instance. See notes below.//
As regards what needs to be done with your
$, you probably need to perform a
noConflict equivalent operation.
Here are some random thoughts:
- backup the existing
$globals, if any (ala
- set your
- "statically" initialise your library, allowing it to glom onto your
- save you
$somewhere that you can ref it again easily e.g. some other special/private namespace
- restore the global namespace to its original state (ala