Hey! I’m here with another general question. (No Playground link today, sorry)
I’ve been reading into this feature some JS development tools have called dynamic imports, where you can place the import statement inside the code itself, which allows a JS bundler to split your code into several smaller files that only need to load when called by the program. Here is a video showing an example of this in Vite at timestamp 1:40.
It makes me wonder though- is there a way to split Babylon.js code into smaller chunks for lazy loading? Or is it not necessary for how the engine loads itself? In other words, is there a workflow for making Babylon.js load pieces of code only when called instead of loading the entire JS file at once?
You can as you would normally do from your own modules, lets say load first the scene and stuff and later the loader for instance. I am honestly not sure it would bring anything tbh as most of the time you will need most of it in your scene.
As @sebavan said it should be totally doable.
I haven’t tried it yet but just a thought, maybe you can have like welcome screen when you wait for the user action (clicking start button or whatever) and you actively start loading the next scene.
So it gives you faster welcome screen for the user (because less assets are needed for the first screen) and faster starting the scene (as it would be loaded from the very beginning).
Ofc heavy assets can/should be lazy loaded asynchronously when needed.
Pretty much what sebvan and neu5 said. We already use it to break functionality up for different platforms. If you don’t import certain parts of Babylon in one platform for instance, it won’t be contained in that chunk when requested
Also making sure the first chunk is tiny as possible and just whats needed to get loading
My biggest use of it is the inspector
Thanks for the replies! I’ll give this a try when I do a multi-scene project and let you know if I run into any issues