Fast load times are crucial for Web-based applications, especially on mobile devices which might need to download application resources on a slow mobile network. Slow load times can result in a poor user experience and high bounce rate. Therefore, it’s important to optimize your Web build for mobile.
Web-based mobile applications work best when you have a small build and performant code because there’s less data to download, less data to store on a user’s device, and less data to load during initialization, which speeds up load times.
For Web optimizations not specific to mobile, refer to Optimize your Web build.
Use these recommended settings to make optimizations specific to Unity Web platform for mobile:
Recommendation | Description |
---|---|
Optimize for size | Disable development buildA development build includes debug symbols and enables the Profiler. More info See in Glossary settings and optimize your build for disk size (Disk Size with LTO). |
Use Brotli compression | Use the Brotli compressionA method of storing data that reduces the amount of storage space it requires. See Texture Compression, Animation Compression, Audio Compression, Build Compression. See in Glossary method to compress your Player build. |
Use the Unity Addressables system | Use the Unity Addressables system for assets. |
Optimize your audio files | Reduce the amount of disk space your audio takes up. |
Optimize the graphics in your project | Reduce the amount of disk space your graphics take up. |
Change the graphical quality level | Lower the quality level to make a faster build. |
A smaller build size is better for mobile because there’s less data to download, which usually makes load times shorter and uses less storage on the user’s device.
To make your build as small as possible, disable development build settings and optimize your build for disk size:
Go to File > Build Profiles.
Select Web.
Disable Development Build if enabled.
Set Code Optimization to Disk Size with LTO.
Note: Optimized builds with LTO can take a long time. Only use this optimization for final release or if you need to test performance. Use a faster build option during development.
For other settings that impact build size, refer to Recommended Player settings to optimize your Web build and Remove unused resources from your Web build.
If you have a script that edits settings and you want to enable the Disk Size with LTO setting with C#, add the following code to your script:
// Set Platform Settings to optimize for disk size (LTO)
UnityEditor.WebGL.UserBuildSettings.codeOptimization = UnityEditor.WebGL.WasmCodeOptimization.DiskSizeLTO;
Brotli compression is a setting where Unity pre-compresses for you while it builds. Brotli-compressed files are smaller than gzip-compressed files, which can reduce your build size.
However, Brotli takes a longer time to compress. Also, Chrome and Firefox only natively support Brotli compression over HTTPS. If that’s not suitable for your application, consider Gzip compression instead.
To use the Brotli compression setting:
Make sure your web server is configured to serve Brotli files with the correct encoding. For more details, refer to Deploy Web application.
Access the Player settings (Menu: Edit > Project Settings > Player).
Click on the Web settings tab.
Expand the Publishing Settings section.
Set Compression Format to Brotli.
If you have a project settingsA broad collection of settings which allow you to configure how Physics, Audio, Networking, Graphics, Input and many other areas of your project behave. More info
See in Glossary script and want to change the compression format with C#, add the following code to your script:
// Set the compression format to Brotli
PlayerSettings.WebGL.compressionFormat = WebGLCompressionFormat.Brotli;
Mobile browser applications need short load times to decrease user bounce rates. To keep initialization times short, instead of loading all assets at startup, use addressables to load assets only when your application needs them. Defer the loading of certain assets until after your game loads.
For these changes, make sure to update StreamingAssets/aa/catalog.json
with any new addressable files you make.
For more information about addressables and how to set them up, refer to Addressables.
To optimize your addressables further, try the following:
Sort your addressables into groups so that you reduce the number of asset bundles. The smaller the amount of asset bundles, the smaller the build size. For more information about addressable groups and how to create them, refer to Manage and create groups.
If you have a lot of audio files in your project, it’s best to compress your files to lower the size of the audio files. However compressed audio can result in lower quality audio. For information about compression formats, refer to Audio ClipA container for audio data in Unity. Unity supports mono, stereo and multichannel audio assets (up to eight channels). Unity can import .aif, .wav, .mp3, and .ogg audio file format, and .xm, .mod, .it, and .s3m tracker module formats. More info
See in Glossary.
Complex graphics can use up resources and make your build larger and less performant. But there are ways to optimize your graphics to reduce your build size and improve performance. To optimize the graphics in your build, try the following:
ASTC compressed texture types give small texture sizes and save some download time. Where ASTC isn’t supported, consider ETC2. For more information, refer to texture formatsA file format for handling textures during real-time rendering by 3D graphics hardware, such as a graphics card or mobile device. More info
See in Glossary.
To use ASTC compressed textures:
Select your texture asset in your project to open the Texture Import Settings window.
Select Web settings.
Enable Override For Web.
Set Format to one of the ASTC block options.
If you use ASTC compressed textures, try to use a larger block size for the compression. ASTC supports block sizes between 4x4 and 12x12 texels. Larger block sizes result in lower quality textures but smaller builds. For a good balance between quality and size that optimizes for download time over a mobile network, consider using 8x8. If download times are still too slow, try increasing the block size. For more information, refer to Recommended, default, and supported texture formats, by platform.
To set the block size of an ASTC compressed texture:
Select your texture asset in your project. The Texture Import Settings show.
Select Web settings.
Enable Override For Web.
Set Format to one of the larger ASTC block options, for example, RGB(A) Compressed ASTC 8x8 block.
The recommended best practice is to set the graphical quality level to the fastest option. The faster option results in a smaller build.
To change the graphical quality level:
Access the Quality settings (Menu: Edit > Project Settings > Quality).
Select the Low or Very Low quality level.
However, the fastest setting can impact the visuals of your application, so make sure that your application looks how you need it to look.
If you have a project settings script and want to change the quality level of your project in the script, add the following code:
// Set the quality level to Very Low (index 0)
QualitySettings.SetQualityLevel(0, true);
The SetQualityLevel()
function takes the index of the Quality Level matrix as a value. SetQualityLevel(0, true)
in this case is the Very Low setting, or the first option in the Quality Level matrix. To change it to Low or the second option, use SetQualityLevel(1, true)
instead.