rhyek/vue-bootstrap-toggle

Bootstrap toggle initiated twice

Closed this issue · 7 comments

Bootstrap toggle can load twice.

Related #1

Hang on, isn't this run while compiling and not in the actual browser? that might be the cause?

rhyek commented

Sure, the require function is transformed to something else by webpack, but the module still is only imported if the condition passes.

rhyek commented

I just ran a couple of tests. This only happens in the following scenarios:

  • You have a script tag loading bootstrap-toggle.js after you've loaded your app.js.
  • You have a script tag loading bootstrap-toggle.js before your app.js, but you also have jQuery loaded twice. This could happen when having a script tag loading it and also having it as a dependency in your app.js. When this happens, the check I'm doing here will always return false and load bootstrap-toggle a second time. Otherwise, the check does it's job.

In general, you should never include bootstrap-toggle.js anywhere in your code.

I'm going to close this as I feel I can't really do anything here. This is more an issue of having well organized dependencies in the project.

Let me know if there's any other way I can help you!

Primary problem is that many projects/plugins/libraries often directly ask you to place it in the html file.

rhyek commented

It is understood that wrappers for use in popular JS frameworks will generally already include those dependencies for you under the hood.

But for example in the case of bootstrap-toggle, you put the css and javascript in the site and it works.

Then you try e.g. this wrapper, and the previously added elements can be easily forgotten or overseen.

rhyek commented

This is more an issue of having well organized dependencies in the project.