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
0Written by Anton Ageev
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
projectcleverweb
309.1K
mcansky
156.1K
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#