---
title: "Rails 5 disables autoloading while app in production"
description:
  "In Rails 5 autoloading is disbaled after booting the app in production mode
  by default"
canonical_url: "https://www.bigbinary.com/blog/rails-5-disables-autoloading-after-booting-the-app-in-production"
markdown_url: "https://www.bigbinary.com/blog/rails-5-disables-autoloading-after-booting-the-app-in-production.md"
---

# Rails 5 disables autoloading while app in production

In Rails 5 autoloading is disbaled after booting the app in production mode by
default

- Author: Shailesh Kalamkar
- Published: August 29, 2016
- Categories: Rails 5, Rails

This blog requires understanding of what is `autoloading`. If you are not
familiar with that then please refer to
[Autoloading and Reloading Constants](http://guides.rubyonrails.org/autoloading_and_reloading_constants.html)
article on Rails Guide.

## Eagerload paths

Autoloading is [not thread-safe](https://github.com/rails/rails/issues/13142)
and hence we need to make sure that all constants are loaded when application
boots. The concept of loading all the constants even before they are actually
needed is called "Eager loading". In a way it is opposite of "Autoloading". In
the case of "Autoloading" the application does not load the constant until it is
needed. Once a class is needed and it is missing then the application starts
looking in "autoloading paths" to load the missing class.

`eager_load_paths` contains a list of directories. When application boots in
production then the application loads all constants found in all directories
listed in `eager_load_paths`.

We can add directories to `eager_load_paths` as shown below.

```ruby
# config/application.rb

config.eager_load_paths << Rails.root.join('lib')
```

## In Rails 5 autoloading is disabled for production environment by default

With
[this commit](https://github.com/rails/rails/commit/a71350cae0082193ad8c66d65ab62e8bb0b7853b)
Rails will no longer do Autoloading in production after it has booted.

Rails will load all the constants from `eager_load_paths` but if a constant is
missing then it will not look in `autoload_paths` and will not attempt to load
the missing constant.

This is a breaking change for some applications. For vast majority of the
applications this should not be an issue.

In the rare situation where our application still needs autoloading in the
`production` environment, we can enable it by setting up
`enable_dependency_loading` to `true` as follows:

```ruby

# config/application.rb

config.enable_dependency_loading = true
config.autoload_paths << Rails.root.join('lib')

```

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-disables-autoloading-after-booting-the-app-in-production)
