Skip to content

Instantly share code, notes, and snippets.

@averyvery
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save averyvery/8d28384543c7680f5b51 to your computer and use it in GitHub Desktop.
Save averyvery/8d28384543c7680f5b51 to your computer and use it in GitHub Desktop.
"Production mode" in a Rails development environment

Why do this?

  • Performance evaluation. Without minification and gzip, you can't always make accurate decisions regarding filesize changes, or do reasonable network speed testing locally.
  • Cache-busting. By compiling your files and saving them with unique names, you're removing the need to clear the browser cache when testing on mobile devices and in older IE.
  • Catching bugs.
    • This is rarer now than it used to be, but uglify has historically created occasional issues in IE8. Better to catch them locally than on integration.
    • Running in production mode exposes problems related to explicit filenames, since a production deploy can change filenames and break related code.

Okay, how do I do it?

Temporarily add these guys to your environments/development.rb

### TEMPORARY SETTINGS START HERE

# disables the default debug mode, which loads each JS dependency individually
config.assets.debug = false

# renames files with a unique cachebusting string. 
# generally useful in local development, and can expose issues that could appear on production
config.assets.digest = true

# enable live compilation, so there's no need to run precompile
# this will slow down your pageloads when enabled
config.assets.compile = true

# enable gzip in development
config.middleware.insert_before ActionDispatch::Static, Rack::Deflater

# compression
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :scss

Why only temporarily?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment