Hi!
Love Stimulus and have been working on a high-traffic Stimulus-powered site for some time.
The site is multi-page SSR ( not a rails project, we use Stimulus with Shopify ).
Looking to optimize things a bit with a refactor and was curious about best practices here.
For example, we have some controllers that load on every page ( like header, cart, etc ) and others that only run on a few or single pages ( like lookbooks, contact pages, etc ).
To-date, we have been using the webpack loader helper and all our controllers get bundled up to one javascript file. This is fine, but that single file has grown with the site and our initial page loads are getting slower.
What we are trying to do, is have some global controllers and some entrypoint-specific controllers, but run into an issue across multiple ES6 imports when it comes time to .start();
We could import each controller needed on each page entry point, but that leaves so much room for error ( and lots of repetition with our global controllers ).
Would love to hear if there are some ways to say have a main.js that starts stimulus then register other controllers to it based on the entrypoint ( Dynamic import and register? ).
I went through through all the github issues and posts here, but nothing really fit the bill. Closest was:
and
We have about 100 or so controllers, so wanted to kinda talk it out a bit before going in too deep.
Thanks in advance for the help!