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
Written by Anton Ageev
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Filed Under
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#