9

The question jQuery plugin file including the jQuery library came up today on stackoverflow, and I strongly advised against including jQuery in the plugin.

I didn't really get any support from others on this; in fact there was more support to include jQuery than not. Is this ok or are there good reasons not to do this? I think it's a really bad idea as I think it should be up to the developer using the plug as to what version of jQuery is being used.

mcgrailm
  • 191
  • 7
  • Include the source inside the file or programmatically? –  Jun 03 '11 at 14:47
  • 2
    As far as I can tell there are 3 answers to the question that you linked to, none of which say anything other than "Don't do that! But if you did..." I'd not call that support for including jQuery. – Ed James Jun 03 '11 at 14:49
  • IMHO if you give a solution then you are supporting it, you can't play both sides of the fence. and if you upvote the solution then you are also saying "I support this" – mcgrailm Jun 03 '11 at 14:52
  • 3
    Not really. If you're upvoting the solution you're saying "This is a good answer *to the question*". The OP on that topic didn't ask whether to include jQuery, he asked how, therefore answers that tell him how are good answers. – Ed James Jun 03 '11 at 14:54
  • @Ed Woodcock I think we'll have to just disagree but to me the good answer to "how" would be NOT to; IF you think it should not be done – mcgrailm Jun 03 '11 at 15:01

3 Answers3

8

I wouldn't even think of doing it.

For one thing most people will already have a copy of the jQuery framework included in their app if they're using jQuery plugins, which means that you're both loading it twice (making http requests slower) and exposed to possible conflict problems.

For another thing, oftentimes people use things like Google's API or another CDN to deliver their external JS libraries, and in that case you're, again, just making your site load times longer.

As for the version of jQuery: If your plugin only works on 1.5 (there were some changes to thinks like attr() in 1.6 that could feasibly break things, so I'll use 1.5 as an example) you should let people know, but not force them to use a specific version. For all you know they might want to take your plugin and expand it to do other stuff which needs 1.6. Sure, they'll have to fix whatever bugs there are in the base plugin, but so what?

Ed James
  • 3,489
  • 3
  • 22
  • 33
7

Initially I was of two minds on this one:

  1. Only by having each plugin include its own version of jQuery can you be certain of the right rev.
  2. You are so not in control of your project if you allow random people (including past versions of yourself) to determine your page-weight or introduce arbitrary/unknown/unknowable weirdities into your code.

#2 makes my skin crawl, so it wins the argument.

So my answer is No, it's not OK. Pick your plugins, make sure they play well together at a particular jQuery rev and stick with it.

Peter Rowell
  • 7,468
  • 2
  • 29
  • 33
0

Absolutely not! It's like including a vehicle when someone purchases a set of tires.

Plugin is addition to something, not a copy of it with addition.

Alexus
  • 2,368
  • 15
  • 24