Wednesday, February 3, 2016

Mutatis mutandis (2): Disabling sprockets is dangerous



Among many options you have when you create a Rails application using the command line, there is a flag --skip-sprockets. This flag allows you to disable rails Assets Pipeline.

Since Rails 3 the assets pipeline is systemic and sprockets-rails is inserted by default in the app Gemfile.

According to Rails documentation: "The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass and ERB."

In other words, the assets pipeline is the Rails subsystem which allows you to manipulate easily your application assets, like images, javascript files and other things.

Why would one disable this? Who knows?!

But our best advice is: DON'T DO IT, UNLESS YOU REALLY KNOW WHAT YOU ARE DOING!

There are many reasons for this advice. Rails documentation gives some of them when it says that disabling sprockets will prevent sass-rails and uglifier gems to be included in your app Gemfile. Without these gems you won't have assets compression and this will penalize your app in terms of bandwidth, since assets will be loaded uncompressed. But this is not the worst part.

Just yesterday coldnebo, a Rails developer, opened this issue at GitHub Rails page: rails --skip-sprockets option creates many undocumented issues for the unwary #23431

Clicking on this link you'll see good reason. But if you decide not to click, here is a summary:

  • jquery-rails won't work properly and this will break, among other things, your layout if you use Bootstrap, which depends on jQuery.
  • gems active-scaffold and cells won't work properly either
  • constructs like form_for and ajax won't work, because these features depend on jquery-ujs, which is inside jquery-rails gem, which, as we said above, will be broken by --skip-sprockets
But what frightens us most is the fact that these issues are NOT documented anywhere!

So, be careful when you try to change this Rails default. The rule here is: if you don't really know what the assets pipeline does, and how it does, then you are not entitle to disable it.