开发者

Embed open source libraries or plugins in a jQuery plugin

When building a jQuery plugin, do you 开发者_Go百科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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜