Cjmarkham
Cjmarkham

Reputation: 9681

Rails external JS as gems

Is there any benefits to including external JS as gems? Eg (JQuery, bootstrap etc). Is it worth including these scripts within the asset folder or using their gems.

I know most of the gems aren't made by the actual script authors and that a gem can be updated where as I would need to update the individual scripts as needed. Just want to know if there are any other benefits.

Upvotes: 1

Views: 38

Answers (1)

joelparkerhenderson
joelparkerhenderson

Reputation: 35443

Use the gems, if they work reliably for you.

  1. Easier updates, typically with a Gemfile and bundler.

  2. Gems can be better organized. For example a gem can contain files for javascript, css, icon images, binary commands, etc. When you keep things organized this way it tends to be easier.

  3. Testing coverage can be presumed. The gems work, and ideally have their own tests, so your app's test suite doesn't need to cover the gems' internal units. Your app can still do integration testing as usual.

My personal experience is that the gems are not 100% reliable especially if you have a need to track the newest JS updates.

Also take a look at rails assets, which is akin to bundler plus bower: https://rails-assets.org/ (It's the best of both worlds for tracking rapidly-updating JS libraries)

Upvotes: 1

Related Questions