O'Reilly logo

Crafting Rails 4 Applications, 2nd Edition by José Valim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Code-Loading Techniques

To understand why we need to explicitly turn on allow_concurrency, we need to analyze the mechanisms available in Ruby and Rails to load code.

The most common form of loading code is Ruby’s require method:

 
require ​"live_assets"

Some libraries work fine by simply using require, but as they grow, some of them tend to rely on autoload techniques to avoid loading all their files up front. Autoload is particularly important in Rails plug-ins because it helps application boot time to stay low in development and test environments, since we load modules only when we first need them.

Autoload techniques

We’ve used Ruby’s autoload in this chapter with the LiveAssets::SSESubscriber class:

 
module​ LiveAssets
 
autoload :SSESubscriber, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required