0

I try to release a Js Library that need jQuery. Which the best way to include it? I have now this approach:

        if(typeof jQuery == 'undefined'){

           /*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */
           !function(e,t){"use st......
        }
       //start my code below

But if the loader site has a older version of jQuery?.. How to handle compatibility with my code? Example: I use the .on method for events, but old release has .bind

Thanks!

Ste
  • 1,497
  • 8
  • 33
  • 63
  • You might find [this question](https://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page) useful. – Nebula Mar 15 '18 at 14:16
  • I'm not sure about common practice but any 3rd party API I have used so far informed me of their requirement, needing jQuery v x.xx minimum and left it up to me to have jQuery. Because jQuery is a public API and unless you are using a custom version I would **not** pack it along your API, leaving the user the freedom to use which ever version they need for their project and worrying about compatibility to your API themselves. Imagine all APIS packing their own version of jQuery, I assume that would be a dependency nightmare. – Nope Mar 15 '18 at 14:16
  • You should do like everyone else does: tell your users that they need a minimum version of jQuery for your plugin to work. And it's a bad practice to include jQuery's source in your plugin. If you want to support older versions, you can create a plugin.legacy.js with adapted code in it. – Phiter Mar 15 '18 at 14:17
  • 1
    You can check the version with `jQuery.fn.jquery` or `jQuery().jquery` – j08691 Mar 15 '18 at 14:17

0 Answers0