Currently, the bridge generates a virtual module which uses import() with the webpackMode comment to make them eager or lazy.
But the way this @symfony/controllers module is consumed in the main entrypoint means that all the controllers are loaded on all pages to be registered. This makes the lazy-loading useless as you would load all chunks on all pages.
I agree indeed. That's something that was discussed but not implemented before the release. We should have a deeper look, and probably ship a behaviour to easily leverage that from the assets/controllers.json file.
Currently, the bridge generates a virtual module which uses
import()
with thewebpackMode
comment to make them eager or lazy. But the way this@symfony/controllers
module is consumed in the main entrypoint means that all the controllers are loaded on all pages to be registered. This makes the lazy-loading useless as you would load all chunks on all pages.I discovered https://github.com/danieldiekmeier/stimulus-controller-resolver which allows to actually lazy-load some modules only if they are used in the page. It might make sense to use that.