Why Does Bootstrap Require jQuery? [closed]
Asked Answered
E

2

30

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 Jan 2019: According to the Bootstrap docs, v5 is dropping the jQuery dependency, so hopefully that will arrive soon.

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

Erickson answered 10/10, 2017 at 20:16 Comment(7)
It's popular - the trend chart shows it still higher than the other frameworks. The devs have experience writing it. You only need it for the interactive elements of Bootstrap.Allantois
It seems that asking about the motivations that led the BS development team to use jQuery is really off-topic here. Why not ask them?Cervin
This is more of an opinion question, as it is currently framed. You might be able to remove the editorializing, venting, and snark to make it more productive. The technical reason is that they use Jquery selectors in the Javascript implementation, like it or not it is a dependency.Gilder
jQuery-3.2.1.slim.js is less than 24k when minified and gzipped (23896 bytes), so I'm not sure how you consider that "is quite a large and bloated framework". It doesn't look like you've come to actually ask a real question, but came to try and validate your preconceived bias. Vue btw is 20k when minified and gzipped as well, do you consider that new and bloated?Gadhelic
Points taken, all. I actually love jQuery and use it in almost every project. Recently I've been digging into a lot of the literature on modern SPA frameworks like Angular, Redux, React, Vue, etc., and was surprised/disappointed to find how many authors do seem to have a bias towards jQuery. It seemed like newer developers are staying away from jQuery, so I was wondering why BS didn't.Erickson
My question #4 above is the one that I think most warrants an answer. But as @Cervin said, it's probably better directed to the devs themselves (e.g., on GitHub) rather than hereErickson
More people (including myself) seem to be bothered by Bootstrap's use of jQuery. In particular, there is an npm package bootstrap-css-only. Also, the new w3-css presents the avoidance of Javascript as a selling point.Simitar
A
20

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.

Assimilable answered 10/10, 2017 at 20:46 Comment(1)
@Inertialboogie "Shortsightedly" is the appropriate word here; I did not realize that BS has been around since 2011! That pretty much explains it, though I'm curious to know whether they would've made the same choice today. The general consensus of this post though, seems to be that I should just asked them directly :PErickson
G
2

Jquery is a popular frame work and lots of developers have experience writing in it, making their documentation easier to digest. It's also very good at dealing with a lot of the cross browser quirks that javascript presents.

If you really don't want to use Jquery, there is bootstrap native: http://thednp.github.io/bootstrap.native/

Gasometry answered 10/10, 2017 at 20:22 Comment(1)
Thanks for your answer! I had come across Bootstrap Native before, but am always wary of using third-party knock-offs. Still, it might be worth a tryErickson

© 2022 - 2024 — McMap. All rights reserved.