Clean solution to split code and assets (regarding ammo.js)

Hi fellow devs,

Is there a clean way of splitting games into code / assets when publishing?

If you have an iOS App in the App Store, which loads a HTML5 game, the Apple policy doesn’t allow to load (Java)Script files from external sources, because they might “change the functionality of the app after review”. So i want to pack the source files into the app, but load assets from an external server (Azure/Amazon/whatever), in order to don’t bloat the app size too much.

So one could set the ASSET_PREFIX from the “__settings__.js” to an external server, which already loads everything located files/assets from the specified URL instead. The problem is, that ammo.js, ammo.wasm.js and ammo.wasm.wasm are also stored in the assets, and not along with other source files.

Is there a simple way, to put those 3 source files outside of the assets folder (maybe under the root folder) and reference to it?

It would also be nice to have a similar solution for glsl, html, css and json files, since I don’t know how strict Apple sees them as “changing functionality after review” of the app.

Any hints appreciated!
Best,
Rene

1 Like

Hi @dexter_deluxe,

You can definitely do that, the assets registry allows you to load assets remotely at any point:

https://developer.playcanvas.com/en/api/pc.AssetRegistry.html#loadFromUrl

And for the ammo wasm files you can do something similar though that should happen before the pc.Application instance boots.

But before you go there, even as I am aware of Apple’s strict policy when it comes to the App Store, can you verify that is the case with HTML5 content?

There are a lot of cases of native iOS apps that load HTML5 content remotely (Snapchat Games and GameBytes to name a few).

Are you looking to wrap the HTML5 into an app as a standalone app? Or have your app as a portal?

@Leonidas We are not trying to manually load assets via the asset registry, we try to load assets from a different server during the initial loading process of the playcanvas app. Would we have to rewrite/monkey-patch the app initialization process to use pc.AssetRegistry#loadFromUrl? Is the AssetRegistry even available this soon?
Development of our game is already finished, we are just trying ship the build as 2 zipped folder and have the game load the assets from a different location than its own.

@yaustar Our game will run inside another app, one that provides a lot more HTML5 games than just ours. The app should be as small as possible for the appstore, but as @dexter_deluxe mentioned, Apple doesn’t allow code, binaries, scripts or anything that might alter the functionality of the app to be loaded afterwards. So the solution we are trying to accomplish is to ship the app with all the code necessary and load images/models etc from another server.

1 Like

Ah, I see. I’ve been working on some scripts that embed files into a single HTML and this sounds very similar.

This is a bit tricky and you may want to use a custom/patched engine and loader for this that checks the asset type and if it is a script type or WASM module, to add an absolute URL prefix to load the file locally instead.

Any asset, even PNG can actually be just a javascript file (inside). So you can load them from remote server which will go against conditions you’ve provided.

You are free to modify engine files, to add custom loading rules, separate per asset type/extension.