Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, sprockets, google closure and advanced opts

I've added the closure-compiler gem to my Gemfile and set

config.assets.js_compressor = :closure

in the config/environments/production.rb file.

I believe this defaults to using the SIMPLE_OPTIMIZATIONS compilation level and I was wondering if there is a config variable I can set somewhere to specify the advanced level instead.

I tried digging through the sprockets code but haven't found a way to pass options to the js_compressor yet.

like image 717
Webdev Avatar asked May 14 '13 18:05

Webdev


People also ask

What are rails Sprockets?

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.

Which of the following are the three compilation levels that can be applied to the JavaScript code to define the degree of compression and optimization required?

The value of this parameter indicates the degree of compression and optimization to apply to your JavaScript. There are three possible compilation levels: WHITESPACE_ONLY , SIMPLE_OPTIMIZATIONS , and ADVANCED_OPTIMIZATIONS .


1 Answers

Check out this issue: https://github.com/rails/rails/issues/2693

To put in simple terms, the given solution is:

# config.assets.js_compressor = :closure
require 'closure-compiler'
config.assets.js_compressor = Closure::Compiler.new(compilation_level: 'ADVANCED_OPTIMIZATIONS')
like image 198
Alcides Queiroz Avatar answered Oct 13 '22 21:10

Alcides Queiroz