Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Does Bootstrap Require jQuery? [closed]

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.

like image 203
Rabadash8820 Avatar asked Oct 10 '17 20:10

Rabadash8820


People also ask

Why did Bootstrap stop using jQuery?

The Bootstrap 5 framework has removed jQuery as a requirement. It saved 85KB of minified JavaScript, which could be significant as Google starts to use page speed as a ranking factor for mobile web sites, and soon for desktop web sites as well.

Does Bootstrap still require jQuery?

Bootstrap 5 is designed to be used without jQuery, but it's still possible to use our components with jQuery. If Bootstrap detects jQuery in the window object it'll add all of our components in jQuery's plugin system; this means you'll be able to do $('[data-bs-toggle="tooltip"]').

Does Bootstrap require JavaScript?

Many of our components require the use of JavaScript to function. Specifically, they require jQuery, Popper. js, and our own JavaScript plugins.

Should Bootstrap Bootstrap min js file be loaded before or after jQuery?

Note that the functionalities of some JavaScript components like tabs and dropdowns depend on popper. js and jQuery. Hence, before loading the Bootstrap JavaScript file, include the jQuery and Popper CDN before loading the bootstrap. min.


2 Answers

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.

like image 190
Simmetric Avatar answered Oct 20 '22 16:10

Simmetric


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/

like image 2
jsldnppl Avatar answered Oct 20 '22 15:10

jsldnppl