Why Does Bootstrap Require jQuery?

Rabadash8820 picture Rabadash8820 · Oct 10, 2017 · Viewed 10.4k times · Source

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 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.

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.

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

Answer

Simmetric picture Simmetric · Oct 10, 2017

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.

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