Fork me on GitHub

I'm trying to understand code splitting with shadow-cljs I want to keep my app multi-paged to keep things familiar for me, but I have some pages where I need some interactivity. I think how code splitting is described is what I want. But I'm not sure I understand what is meant by the :shared module. Does it mean if home, login, and protected require something from common (via ns)? Or would require s get compiled into each module and shared is something else?


I guess what I'm asking is, do I need to copy-paste the :required namespaces in my cljs files in the :shared module definition?


I think I got it working. So I left :shared empty as mentioned in the 'tip'. And I added both the shared.js and login.js scripts in the html page.


Thank you. I haven't seen that.


ah that's specifically talking about splitting/lazy-loading React components. How should I approach splitting without Reagent/React? e.g. I want to compile self-contained scripts that are only needed in specific pages. Would I need separate :builds entries for each script? Does that end up with each build having some duplication of the Clojurescript runtime?


no, the exact same stuff applies. you seem to have figured out the correct approach


shared is everything that multiple pages may use


login is only what login uses


you can just load them directly via html script tags, no need to load them dynamically driven by react components


so if you only need that then you seem to be done


with :target :esm it would even be fine to just include the login.js file and let it load the rest itself


ah sweet. Thanks Thomas! That clarifies things.


if you want a more "modern" appraoch that is. but :target :browser is still totally fine and a lot more flexible in many ways

👍 1