Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does rails require JavaScript Runtime?

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?

like image 390
CuriousMind Avatar asked Mar 12 '12 18:03

CuriousMind


People also ask

Does rails use JavaScript?

Rails uses a technique called "Unobtrusive JavaScript" to handle attaching JavaScript to the DOM. This is generally considered to be a best-practice within the frontend community, but you may occasionally read tutorials that demonstrate other ways. When clicked, the link background will become red.

Does rails require Nodejs?

Most Rails applications will not require Node. js, given the new defaults. Developers can use the JavaScript bundler they prefer, as Webpack is no longer required. The same approach has been taken with CSS bundlers that rely on Node; Rails 7 files require only a compiled application.

Is node JS faster than Ruby on Rails?

Performance speed If we compare the speed of Ruby on Rails vs Node. js, even experienced Ruby on Rails developers acknowledge that the framework is slow. While its speed improves with every version, it's still a lot lower than Node's. There are many reasons for the performance delay.

Which is better Ruby on Rails or node JS?

Ruby on Rails is considered to be faster and lighter, as compared to the Node. js as here you can easily perform tasks, like the migration of database in just performing a few commands. The learning curve is partially less than with Rails.


2 Answers

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.

like image 105
tybro0103 Avatar answered Oct 04 '22 14:10

tybro0103


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.

like image 40
Ed Jones Avatar answered Oct 04 '22 13:10

Ed Jones