Rectangle 27 1

javascript Ruby on Rails how require is executed in application.js?


Anything starting with a // is a Javascript comment.

Sprockets on the server side scans the JS file for directives. //= is a special Sprocket directive. When it encounters that directive it asks the Directive Processor to process the command, require in this example. In the absence of Sprockets the //= require .. line would be a simple JS comment.

Thanks a lot for the detailed answer and the video link, too.

Usually, you want to concatenate all your app JS files and then minify them into 1 master JS file and then include that. I recommend reading the YSlow best practices on this.

Note