New Discussion

Notifications

You’re not receiving notifications from this thread.

How to add Lazy Load Hooks to Rails Plugins Discussion

2
General

Have you used lazy load hooks to extend a gem with some interesting features?

Thanks for sharing this — it’s a really useful topic, especially as Rails apps get more complex and performance becomes more critical.

Adding lazy load hooks to Rails plugins is definitely a smart move if you're trying to reduce boot time and avoid unnecessary memory usage. If you're using ActiveSupport.on_load, it's a great way to defer loading code until the specific framework component is initialized. Something like:

ActiveSupport.on_load(:action_controller) do
  include MyPlugin::ControllerMethods
end

This way, your plugin doesn't pull in Rails components prematurely, and it integrates cleanly when the relevant part of the framework is ready.

Out of curiosity — are you using Zeitwerk for autoloading in your plugin? It plays really nicely with this approach if your plugin is structured properly. I’d love to hear how you're organizing things or if you're hitting any snags with it.

Again, awesome share. This kind of insight helps keep the community sharp.

Are there any words you can guess? Quordle words are a fun way to play word games in a new way. Learn new words and get smarter at the same time! Are you up for a game? If so, let’s begin with the quordle. In this game, you have to find words that make grammatically correct English sentences. This group of word games is also called “Scrambled Word Games” because the goal is to put words back together by using the letters from a given word.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 90,335+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.