Version: 2023.2
Language : English
Recommended Graphics settings to optimize your Web build
Recommended Quality settings to optimize your Web build

Recommended Player settings to optimize your Web build

Use the following recommended Player settings to optimize your builds for the Unity Web platform.

Player settings quick reference

Find these settings under Edit > Project settings > Player. For more information on each setting, refer to the details in Player settingsSettings that let you set various player-specific options for the final game built by Unity. More info
See in Glossary
.

Setting Recommended Setting Description
API Compatibility Level .NET Standard 2.1 Produces smaller builds.
IL2CPP Code Generation Faster (smaller) builds Generates code optimized for build size and iteration.
Managed Stripping Level High Unity does a high level of managed stripping to create a smaller build.

Configure the following recommended settings in the Publishing Settings section:

Setting Recommended Setting Description
Compression Format Brotli Files compressed by Brotli are smaller.
Data Caching Enabled Runs faster since cached data doesn’t need to be downloaded again on subsequent runs (unless the contents have changed).
Debug Symbols Off Debug symbols can slow down your application.
Enable Exceptions None Exceptions can cause overhead.

API Compatibility Level

Use the API Compatibility Level setting to choose which .NET APIs you can use in your project. The recommended setting is .Net Standard 2.1 because this setting produces smaller builds and has cross-platform support. However, you need to check if your platform fully supports .Net Standard 2.1. For other options, refer to Web player settings.

Change the API Compatability Level

To change the API Compatability Level via script instead, add this code to one of your scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary
:

PlayerSettings.SetApiCompatibilityLevel(namedBuildTarget, ApiCompatibilityLevel.NET_2_0);

IL2CPP Code generation

Use the IL2CPPA Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. More info
See in Glossary
Code generation
setting to configure how Unity manages IL2CPP code generation (if your project uses the IL2CPP scripting backend).

The Faster (smaller) builds option is recommended because it creates a smaller build and generates less code which results in faster build times. Faster build times are vital in Web applications. However, this setting can reduce runtime performance.

For more information, refer to IL2CPP overview.

Change the IL2CPP Code generation via C

To enable this setting via script instead, add this code to one of your scripts:

PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget,         
                                       Il2CppCodeGeneration.OptimizeSize);

Managed stripping level

Use Managed stripping level to configure how much the Unity linker process strips unused code from the managed DLLs your project uses. The recommended setting is High because stripping code can make your executable significantly smaller, which is very important in Web applications. However, possible side effects may include:

  • Managed code debugging of some methods may no longer work.

  • You may need to maintain a custom link.xml file.

  • Some reflection code paths may not behave the same.

For more information, refer to Managed code stripping.

Change the Managed stripping level via C

To change this setting via script instead, add this code to one of your scripts:

PlayerSettings.SetManagedStrippingLevel(namedBuildTarget,     
                                        ManagedStrippingLevel.High);    

Compression Format

Choose what 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
format to use for release build files. Brotli is the recommended setting because it has the best compression ratios and Brotli-compressed files are smaller than gzip. Smaller files are best for Web applications. However, Chrome and Firefox only support Brotli if the user accesses the site over HTTPS. Also, although Brotli is supported on most modern servers, there are some servers that do not support it. Make sure that your server supports Brotli.

For more information on compression formats, refer to Deploy a Web application.

Change Compression Format via C# script

To enable this setting via script instead, add this code to one of your scripts:

PlayerSettings.WebGL.compressionFormat = WebGLCompressionFormat.Brotli;

Data caching

Enable Data caching so that Unity caches your contents asset data on the user’s machine. Data caching can make the application run faster. For more information, refer to Cache behavior in Web.

Enable data caching via C# script

To enable this setting via script instead, add this code to one of your scripts:

PlayerSettings.WebGL.dataCaching = true;

Debug symbols

The Debug symbols setting preserves debug symbols and displays original function names of the stack trace when an error occurs, so it’s easier to identify the source of an error. It is recommended that you turn off the Debug symbols option on your final release build because it can make your build unnecessarily large and slow down your application. Enable this setting during development and testing to make it easier to identify the source of an error.

Deactivate Debug symbols via C# script

To deactivate this setting via script instead, add this code to one of your scripts:

PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Off;

Enable exceptions

The Enable exceptions setting lets you choose how to handle errors at runtime. It is recommended that you choose the None option in your final release build because this setting gives the best performance and smallest builds.

However, with this option, any exception thrown causes your content to stop with an error, so it’s best to enable exceptions during development and testing. For more information, refer to Build your Web application and Web Player settings.

Deactivate exceptions via C# script

To deactivate exceptions via script instead, add this code to one of your scripts:

PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None;

Additional resources

Recommended Graphics settings to optimize your Web build
Recommended Quality settings to optimize your Web build