[SOLVED] Load loading screen assets first

Hi everyone,

I’m looking for a way to load the assets of the loading screen first and still preload all other assets. I use six images in the loading screen, that currently get loaded among the other 12 MB of assets. Using preload only for loading screen assets and dynamically loading the other assets on demand is not favoured, because this app will mainly run in China, where such loading processes can take a long time.
I already tried to modify the preload function by moving tagged assets to the front of the asset array, but without success so far.

Any ideas?

Cheers, Patrick

EDIT: resource.getFileUrl() is favoured over direct links in the loading screen script.

If you need the image URLs for the loading screen, they don’t need to be preloaded as they don’t need to be converted to textures, elements etc for HTML.

If you must use resource.getFileUrl(), you can get those when the app fires it’s preload start event as shown here: https://playcanvas.com/editor/scene/783637

Otherwise, it is recommended to use externally hosted images/direct URLS for the preload screen so you don’t have to wait for the asset system to initialise.

1 Like

Thanks yaustar for clarifying my options. Since I won’t maintain my app after deploy, I would like to keep all files in one place, as simply as possible. As a workaround I’ll place them in the project folder and link them directly.

Personally, I would base64 encode the images and embed them directly in the loading screen script.

For example, you could turn this:

        var logo = document.createElement('img');
        logo.src = 'https://s3-eu-west-1.amazonaws.com/static.playcanvas.com/images/play_text_252_white.png';
        splash.appendChild(logo);
        logo.onload = function () {
            splash.style.display = 'block';
        };

Into this:

        var logo = document.createElement('img');
        logo.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPwAAAAdCAQAAAAkusnLAAAJ7klEQVR4AbXbBXAkV5aF4SM1mNnuMdvrMTMzMzMzMzP1hJkd0x5mHjMzMzMzo8zNqNa3s7sZGZZUkC5t/3+AVHpFeV7edxPUZkjqMSzv5sF8kp78LDMWP52SMfkx7J7ly58/ys/zQ36aI8qfb8s9qc+2WbP8+YJ0pDcLZ5usmUUzZ9ozMR15Jffm2nyUZiyf3ZOMymmpzxQ5P8kz+XcaUI67PE8nSc7MdBmXU9KV5rTlvEyRERmcnsyfw5N05eSMTzOWy25ZPQtk+iQj8n6eye3/cVwKohkPWlO6+SEF04vqDvQVJRPNJUq1uZuCr8wkdZzbCAr+Lb1c18Nq0ely80hDbwCsKX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AqjTNe41JdO5z102bDJuHhOWaT19zlekl7uqgpd5pPK/gWkfyYlB6Y6e+SkjEtr/CrHZ4pcmDsyNtVpz0FJhjbcX2bLhpkye+aXqcKw7JLH0j//yNJNPslv8qf/LdI3JdkisyX5XZ2FaHyuaFhTt0lbDspJqcrYJF2Tdo9f2o9j15b3+BgMfidNnM1kPa59XyINnMpwvF5xjy+riHvMWH9ceen3dhF3lydku7sYuLzCjRtfK79V08O7+/GJSRr8rxQYZ3Hz1vEjBe7rQ/ADPA1Oa3oHzhvW6napeH5p6K/BWpWDb3MnuLjJuMvQZZ6ib/9t3Xtq1650AWy38ghnmOWlrvPrxD/6GvzHPqzpvuWcBq6Wup6pxPwtB1/ec+dPpmxyz91hxfhO3CdNXAJcWTn4GOQLaDJuUXC288BSdWpNeTa+yTX8R0QMMgaj7CY1HeghsHKrwTfjaLEHJRtXvAnzvD4EX95l60N7N7jL9qRur7xjxWt34w2qHHysr4um4x7E5zrwuPTyAHCcNPUasISIfUwEd1ihxlR7slw8JmHwj1DwiXZp4H0UdOjfQvC17qv/tuZ99SPsJMpO2lcGSlP3BqeqHnycVyH4nSjYQ3r5PMaaqfLVz1+LiI10AF52vl2s8x+3c4r7dIF7TDkpg19ISdNbJHajZOs+BN/8P2nm6nFZ5SJpZrlofahd9eD7e7zpuIG+BN/Uvaf2n6rf7zDc1CJiRhcboRYjnabYtfrnzLLNr8qQTN/0XNqM5esmf05jrv/B2K5058EfvGY17v+PPf937tXcl6vycVLSlTPLT9aM0TkwiyYZlI4kY3NmkhfTmM7snH2bjBufg7J0kldqbPtpcmaSa1IFOTwrJ5k9bydJvssJOTNbZcMsnfkydZLx+Sgv5e5cnWEp+G85FRWvSO7tpAAAAABJRU5ErkJggg==';
        splash.appendChild(logo);
        logo.onload = function () {
            splash.style.display = 'block';
        };

Use this tool to do the encoding:

4 Likes

Thanks will! I thought about base64 too, but then the ~30% size increase comparing to binary scared me off, since the app is going to run mainly on mobiles. I will test, if it really makes a big difference with the small loading screen assets. Cheers!

With base64, it should compress down pretty pretty well if the server has gzip enabled. It be worth checking the download size on the client using base64

2 Likes

When I download the project as a .zip, the project is already gzipped? I just need to enable gzip on the server? On Unity for example I can select no compression, or compress with gzip or brotli.

Hi @Marks,

Yes, gzip compression works by enabling it on the server for each file type. Then the server is responsible for gzipping each file when it’s requested.

1 Like