25

i wanted to ask if Popper.js is absolutely necessary or not if i don't use dropdown menus. Are there any other parts driven by popper that would not work without the library?

Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160
AndiLeni
  • 481
  • 1
  • 6
  • 16

5 Answers5

35

If you search for "popper" in Bootstrap 4's documentation, the following results will come up:

Tooltips rely on the 3rd party library Popper.js for positioning.

Popovers rely on the 3rd party library Popper.js for positioning.

Dropdowns are built on a third party library, Popper.js, which provides dynamic positioning and viewport detection.

So these are the Bootstrap 4 components that need Popper.js.

Though Popper.js is stated as required for Bootstrap 4, and Bootstrap 4 JS logs an error if it can't find Popper, you can still use Bootstrap 4 JS without Popper, if you don't need tooltips, popovers, dropdowns, nor modals.

For example navbar's JS functionality (mobile menu on the right) works well:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>
Community
  • 1
  • 1
juzraai
  • 5,693
  • 8
  • 33
  • 47
  • 2
    Your answer suits my expectations. Unfortunately modals won't work without popper. – AndiLeni Sep 11 '17 at 12:39
  • 2
    Oh, it seems that the documentation is not complete enough. I add it to my answer (it may be useful in the future). – juzraai Sep 11 '17 at 12:45
  • Something must have been changed, I can use dialogs without popper, but I'm surprised that bootstrap can figure out where to open dropdown in navbar without popper but not any other places – AaA Apr 16 '20 at 05:17
17

Popper.js is not required if you use bootstrap.bundle.js or bootstrap.bundle.min.js instead of bootstrap.js or bootstrap.min.js. That's because the bootstrap.bundle.* libraries contain popper internally. You can download all the bootstrap files from here

Cullub
  • 2,901
  • 3
  • 30
  • 47
Prince Ahmed
  • 1,038
  • 10
  • 10
  • 2
    In bootstrap 4.3.1 bootstrap.bundle.js is bigger than bootstrap.js and I'm pretty sure it includes popper so is pretty much the contrary :( – cancerbero Feb 14 '19 at 20:28
9

Not anymore, check THIS issue It seems Bootstrap has bundled Popper and Bootstrap v4 into a bundle.min.js file that is available if you try downloading now. HERE is a link directly to the bundled min file. Hope that helps someone who is not interested in adding a separate popper file

PirateApp
  • 5,433
  • 4
  • 57
  • 90
5

Alternatively, if you only use the non-Popper JS functionality of bootstrap, you can fake Popper and load bootstrap (thus Bootstrap will work and won't throw an error about Popper being missing):

<script>
    window.Popper = {}
</script>
<script src="js/bootstrap.min.js"></script>
Max
  • 12,794
  • 30
  • 90
  • 142
2

Popper.js is required IF you're using Bootstrap JS. It's not required if you're using only the Bootstrap CSS.

Read the docs

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624