Bootstrap为什么需要jQuery? [英] Why Does Bootstrap Require jQuery?

查看:193
本文介绍了Bootstrap为什么需要jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个问题上搜索了很多次,但从未找到满意的答案.大多数答案似乎只是说"是的,Bootstrap插件确实需要jQuery ".或"是的,如果您不使用jQuery,则可以使用不带jQuery的BS插件".Bootstrap对jQuery的依赖(如其快速启动中所述),至少由于以下原因,我认为这是一个糟糕的设计决策:

I have googled this question numerous times and never found a satisfactory answer. Most answers seem only to say that "yes, Bootstrap plugins do require jQuery" or "yes, you can use BS without jQuery if you don't use the plugins". Bootstrap's reliance on jQuery (as described in their quick start) strikes me as a poor design decision, for at least the following reasons:

  1. jQuery是一个庞大且庞大的框架,现在任何使用BS插件的网站都必须下载它.当然,BS用户可以使用苗条/最小化版本(除非他们想使用jQuery AJAX ),但即使是那些代码,对于Bootstrap以外的任何人都不能使用的库来说,它们的加载时间并不重要.
  2. 随着Angular和React之类的框架变得越来越流行,
  3. jQuery通常似乎不再受到青睐(请参见完成..我们都知道,在创建任何类型的软件包/库时,我们都应该在可行的情况下尝试删除其他依赖项,因为用户想要的是该软件包,而不是一堆其他的绒毛.
  1. jQuery is quite a large and bloated framework, and now any site using BS plugins will have to download it. Granted, BS users can use the slim/minified builds (unless they want to use jQuery AJAX), but even those add not-insignificant load time for a library that may not be used by anything but Bootstrap.
  2. jQuery in general seems to be falling out of favor lately, as frameworks like Angular and React grow more popular (see StackOverflow trends). I know old != bad, and jQuery is still almost ubiquitous on the web, but why did the BS developers choose to rely on an over-decade-old framework?
  3. Simply requiring jQuery to be <script>ed in before BS does not allow for very clear dependency resolution with modern bundlers like Webpack and SystemJS. Again, why didn't they use some kind of module-based dependency?
  4. But most importantly, in my opinion: why did the BS developers choose to rely on a JS framework at all?? In this wonderful age of standards-compliant browsers, most of jQuery's features can now be accomplished with vanilla HTML/CSS/JS. We all know that when creating a software package/library of any kind, we should try to remove additional dependencies whenever feasible, because users want that package and not a bunch of other additional fluff.

那么,尽管有上述所有情况,那么有什么理由使BS开发人员选择依赖jQuery吗?我可能本可以直接在BS开发人员的GitHub页面上向他们询问问题,但我希望将来有这些问题的Google员工可以更轻松地获得SO问题.

So is there some reason, then, that the BS devs chose to rely on jQuery, in spite of all of the above? I probably could've just asked the BS devs directly with an Issue on their GitHub page, but I hoped that an SO question would be more accessible to future googlers with these questions.

2019年1月更新:根据 Bootstrap文档,v5删除了jQuery依赖项,因此希望很快就会到来.

Update Jan 2019: According to the Bootstrap docs, v5 is dropping the jQuery dependency, so hopefully that will arrive soon.

2021年5月更新:Bootstrap v5已发布!如承诺的那样,此版本已删除jQuery,如发布博客文章中所述.

Update May 2021: Bootstrap v5 is out! As promised, this version has dropped jQuery, as described in the release blog post.

推荐答案

事后看来,判断起来很容易(因为您的目光短浅),但在2011年,jQuery并没有被认为是肿或过时的,并且是公认的主要库提供了简单的DOM访问.因此,在这种情况下,使用jQuery非常有意义.

In hindsight it's easy to judge (as you are doing rather shortsightedly), but back in 2011 jQuery was not considered bloated or outdated and was the main proven library that offered easy DOM access. So in that context it made perfect sense to use jQuery.

实际上,六年之后,可能仍然没有另一个具有相同健壮性和jQuery功能集的库.

In fact, 6 years later there may still not be another library with the same robustness and feature set of jQuery.

这篇关于Bootstrap为什么需要jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆