gazay / gon

Your Rails variables in your JS
MIT License
3.05k stars 184 forks source link

ActionView::Base and ActionController::Base should be loaded inside ActiveSupport.on_load hook #255

Closed amatsuda closed 5 years ago

amatsuda commented 5 years ago

Currently, requiring gon immediately requires ActionView::Base and ActionController::Base here for monkey-patching, which results in loading almost everything within actionview and actionpack, and also triggers all :action_view and :action_controller on_load hooks that are defined via apps and bundled plugins.

For postponing those heavy loads, Rails equips ActiveSupport.on_load mechanism as described here. https://guides.rubyonrails.org/engines.html#active-support-on-load-hooks With this hooks properly configured, applications can defer loading Action*::Base until they actually use them, so that they can boot the app faster where they don't use them, e.g. when starting up the Rails console, running model unit tests, etc.

gazay commented 5 years ago

That is amazing! Thank you