Speed up Rails 4 in development mode

1 minute read

Being working with a large Rails project you may face with a problem of a slow page rendering. One of the reasons why this might happen is that your particular page has a lot of assets and browser does huge amount of requests to download them. Fortunately, Rails 4 has a nice feature for preprocessing those assets. You may find the following in config/development.rb:

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = false

With development tools in Safari browser we can notice the difference in both modes.

debug_true

When debug mode is on, browser loads 197 assets (totally 2.50 MB) and renders a page in 14.53 seconds.

debug_false

But when debug mode is off, browser loads only 14 assets and renders the same page in 1.17 seconds, which almost 14 times faster. Wow!

With config.assets.debug = false all assets are bundled into files like application.css and application.js. This is a bit different from production mode and there is no need in server restart to pick up the change of the asset. But this might not always be very convenient in development mode because it will be much harder to debug the front-end part.

Leave a Comment