views:

35

answers:

2

When building a jQuery plugin, do you think it's bad practice to embed the source of another plugin or library that it depends on?

It seems to me that it's a better way to go than requiring users to do multiple <script src="..."> calls or compressing the multiple source files themselves.

+1  A: 

Personally, as a potential plugin user, I'd prefer the multiple <script src='...'> way. First, it gives me more flexibility and control and second, if I already have some of the plugins in my own code, having them in your plugin as well means they'll be included twice. Imagine what would happen if every plugin author included all dependencies in the source. What you think is convenient now will turn out to be a maintenance nightmare later.

Amati
It's a bit like statically including libraries into programs. Dependency, redundancy and versioning hell, here we come!
Delan Azabani
Actually, static linking is a pretty good solution when it comes to standalone applications. There are no dependencies (from user point of view) and there is no versioning hell. Everything is in the program and installation and upgrades are very easy. There may be redundancy but with today's storage size that is not an issue. With plugins it's different - they are not standalone, they will be used alongside other plugins and other code. So the "static" include here won't be a good idea.
Amati
Thanks. You've convinced me.
Trevor Hartman
+1  A: 

I would stay away from embedded in most cases, especially if you're depending on another jQuery plugin. Some cases to consider:

  • What if I'm already using that plugin, a newer version, an older one?
    • At best you're adding the download weight twice, possibly a different version
    • At worst you're breaking my code :)
  • What if I'm trying to debug, is a bug in your plugin?, the other?, still yours because you included it?
    • Which author do I contact?

There are few upsides to this besides saving a few <script> tags, which should be cached on the client anyway...and in my case as well as many others (like SO) the scripts get compressed into one or a few requests.

Most jQuery plugins require dependencies to be added with their own <script> tags, in this case by not going with what most do serves more to confuse or complicate rather than save time. Personally, I'd stay away from the embedding, but to each their own.

Nick Craver
You guys both made some excellent points that I hadn't thought about. I'm thoroughly convinced :) I still wish my plugin users didn't have to do multiple script calls - I personally hate it when a jQuery plugin has a dependency.
Trevor Hartman