What sprockets mean in rails What sprockets mean in rails ruby-on-rails ruby-on-rails

What sprockets mean in rails


Sprockets is a Ruby library for compiling and serving web assets. Sprockets allows to organize an application’s JavaScript files into smaller more manageable chunks that can be distributed over a number of directories and files. It provides structure and practices on how to include assets in our projects.

Using directives at the start of each JavaScript file, Sprockets can determine which files a JavaScript file depends on. When it comes to deploying your application, Sprockets then uses these directives to turn your multiple JavaScript files into a single file for better performance.


/app/assets/javascripts/application.js// This is a manifest file that'll be compiled into including all the files listed below.// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically// be included in the compiled file accessible from http://example.com/assets/application.js// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the// the compiled file.////= require jquery//= require jquery_ujs//= require_tree .

application.js file is known as a manifest and it’s managed internally by Sprockets. When a request comes in for this file Sprockets looks at the manifest and compiles together every file that is mentioned in it and includes their contents before any code in this file.Sprockets will search the loadpath for this file and, in this case, load it from the jquery-rails engine’s vendor/asset/javascripts directory.