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 ...

Get Crafting Rails 4 Applications, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.