What is therubyracer or libv8 for in a rails application?

Weston Ganger picture Weston Ganger · Jan 14, 2015 · Viewed 11.3k times · Source

I was working on a project and was having issues with therubyracer and libv8 often, so i decided to remove them. It seemed to be the only thing that used them as a dependency was less-rails which I wanted to remove anyways.

My main question is what are they for and do I need them in the average application and if so why?

Answer

l3x picture l3x · Jun 30, 2016

There are a few things for which a Rails app might use a Javascript Runtime:

1) The Rails Asset Pipeline requires a Javascript Runtime in order to perform Javascript compression.

2) Certain Rails ActionView Helpers like javascript_include_tag require a Javascript Runtime in order to execute Javascript functions.

Not every Rails application use those features, hence the reason that therubyracer gem is initially commented out in your Gemfile; Furthermore note that you could alternatively use NodeJS as your Javascript runtime.

For details, see:

http://guides.rubyonrails.org/asset_pipeline.html#javascript-compression

http://www.rubydoc.info/docs/rails/ActionView/Helpers/JavaScriptHelper

http://www.rubydoc.info/docs/rails/ActionView%2FHelpers%2FAssetTagHelper%3Ajavascript_include_tag

Proper "Rails" way to perform javascript on specific pages