Rails defaults to jquery and coffeeScript. What if I want to stop using any of this (total)?

The first thing I did was rails new -h , which gave me a vast amount of flags available when creating a new project.

JavaScript'a there concerns only a couple of pieces, namely rails new --javascript and rails new --skip-javascript . I assume that disabling jQuery and CoffeScript are made there, because if you just delete the use 'jquery' in the Gemfile, then it breaks the entire application.

Interested in the possible uses of these flags. What can I write in --javascript except for jQuery (and, I repeat, what to write, in order to disable the use of any library)? What will happen when using the --skip-javascript flag?

  • use ? Maybe gem ? - D-side
  • @ D-side yes, of course. Comments - smellyshovel

1 answer 1

You may not know that jQuery is used there. You can use it directly, via jQuery-UJS (Unobtrusive JavaScript). Parameter :remote , links are not GET 'om, that's all. If you remove it, some things on the pages that many Rails developers are used to will stop working.

If you generate an application with the --skip=javascript flag, the application will be generated without JS assets at all. For reasons unknown to me (in Rails 4.2.6), the uglifier remains, but since it only participates in the build (and there is nothing to collect), the effect will not be noticeable: but if you still want to add something, you will immediately have a minification. Although it can be safely removed, if you do not need it.

At the same time, nothing prevents you from removing JS from an existing project, if you really want:

  • remove relevant gems
  • remove their require from Sprockets manifests in assets
  • remove the connection code from the view
  • if you really want to, erase the relevant empty files

If, after cutting off some kind of “extra detail”, the application exploded, find out why — apparently, what you cut off was still used somewhere. Use version control to not be afraid to do potentially dangerous things.