Last Updated: February 25, 2016
·
786
· antage

Eliminate javascript debug code after assets compiling (Rails 4 only)

Uglifier is able to eliminate unreachable code, so we can get rid of any 'console.log' lines after assets compiling.

app/assets/javascripts/application.js:

if (typeof DEBUG === "undefined")
    DEBUG = true;

if (DEBUG)
    console.log("This is debug message.");

config/environments/production.rb:

config.assets.js_compressor = Uglifier.new(define: { DEBUG: false })
$ RAILS_ENV=production rake assets:clobber assets:precompile
$ find public/assets/ -name "application-*.js" -exec grep console.log {} \; wc -l
0

Have a fresh tip? Share with Coderwall community!

Post
Post a tip