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

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,499
  • 3
  • 24
  • 34
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,518
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,398