Script Preloading

So here’s a bit of a file optimization question. I am working on a project with multiple somewhat large scenes, and I’ve opted to place a preloader in each one that dynamically loads the assets on scene load.

I’ve noticed that when self hosting, the large number of scripts sometimes do not respond to app events when combined with the website’s own js fighting for resources. Since I’m not preloading my scripts, they are not concatenated on publish, which means a large number of GET calls as each scene loads.

I see a couple of different options here, but I’m curious to see which would be the most recommended.

Option 1:
Do nothing. Work to keep the number of scripts as low as possible, and continue to load them as needed by scene.

Option 2:
Pre-load all of the scripts and let Playcanvas concatenate them into one big file.

Option 3: Concatenate individual scene scripts into one file per scene, and load that single file on scene load.

I’m leaning toward Option 3, but I’m wondering if there is something fundamental about this choice that would make me want to avoid it.

Any insight is greatly appreciated!

I think given your constraint, dynamically loaded scenes, if you are sure that there are no common or overlapping scripts (used in more than once scene) that option is your best choice.

Having few network requests is quite important for improving your app loading time. So if your pipeline can accommodate for that custom bundler definitely do that.

Otherwise option 2. may be ok as well if you aren’t loading huge number of scripts per scene and you are ok of having all scripts available from the beginning.

2 Likes

Thank you @Leonidas!

I will go down that path and concatenate my scenes as I complete them.

1 Like