symfony / stimulus-bridge

Stimulus integration bridge for Symfony projects
https://symfony.com/ux
75 stars 15 forks source link

Lazy-load only the necessary controllers #3

Closed stof closed 3 years ago

stof commented 3 years ago

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

tgalopin commented 3 years ago

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.