Why does rails require JavaScript Runtime?

Ruby on-RailsRuby on-Rails-3

Ruby on-Rails Problem Overview


I was installing rails(v3) on my Ubuntu Linux Box & the install failed complaining of missing javascript runtime. I did some lookup & it turns out that rails require a javascript runtime to be installed on the platform its running.

While, Windows has come bundled with jscript by default. My Ubuntu box didn't have a js runtime & I fixed the issue by installing node.js(V8).

AFAIK, a js runtime is required to execute javascript code & rails is just a web framework in which javascript are embedded. Javascript files run only on client machines.

So, Why does rails require JavaScript Runtime?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Look into the Rails Asset Pipeline. It does fancy stuff with JavaScript (and CSS) files. Notably:

  1. It converts CoffeeScript into JavaScript
  2. It combines all javascript files into one
  3. It minifies that file

The JavaScript runtime is used for minification.

Solution 2 - Ruby on-Rails

Railsguides says it has to do with compression:

> You will need an ExecJS supported runtime in order to use uglifier. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check the ExecJS documentation for information on all of the supported JavaScript runtimes.

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

I thought I had seen Rails actually check the validity of both the stylesheets and the javascript in your app, but maybe it was just SASS prepreocessing.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCuriousMindView Question on Stackoverflow
Solution 1 - Ruby on-Railstybro0103View Answer on Stackoverflow
Solution 2 - Ruby on-RailsEd JonesView Answer on Stackoverflow