There is an easy way to do this. In your config/production.rb
you need to set up YUI compressor with munge option:
config.assets.js_compressor = YUI::JavaScriptCompressor.new(munge: true)
Make sure you have compression enabled in the same file:
config.assets.compress = true
And also clean all cached files after enabling this in tmp/cache/assets
and public/assets
.