Browser games

Porting a Unity Game to WebGL Without the Bloat

A Unity web build gets bloated for predictable reasons: engine modules you do not use, unstripped code, uncompressed textures and audio, everything bundled into the first download, and a server that is not set up to deliver compressed files. Fix those in order and a heavy WebGL export becomes a much leaner game that starts quickly. This guide walks through the settings and workflow we use when porting Unity games to the browser.

First, measure what you are shipping

Before changing anything, make a release build and look at what is inside it. After a build, the Unity Editor log includes a report that breaks down size by category (textures, meshes, audio, shaders, scripts) and lists the largest assets. Sort by size and you will usually find a short list of offenders responsible for most of the weight.

Also record what the browser actually downloads. Open the build in a browser with developer tools, disable the cache and note the size of the data, framework and WebAssembly files, plus the time from click to first interaction on a mid-range phone. Those numbers are your baseline. If you would rather hand the port over, our browser game development team does this work regularly.

Build and player settings that matter

In Unity 6 the target is called the Web platform, configured through build profiles. Older versions call it WebGL. Setting names shift slightly between versions, so check the Unity Manual for yours, but these are the levers:

SettingRecommendationWhy
Compression FormatBrotli for release, if your server can serve itUsually the smallest transfer size for the build files
Decompression FallbackOff, if you can configure the server headersThe fallback decompresses in JavaScript, which is slower to start
Code OptimizationFavour disk size for release buildsProduces a smaller WebAssembly binary
Managed Stripping LevelAs high as your project toleratesRemoves unused managed code
Strip Engine CodeOnDrops engine modules the project does not reference
Enable ExceptionsThe most limited option your code works withFull exception support adds size and slows execution
Development BuildOff for releaseDebug symbols and profiler hooks add significant size
Data CachingOnLets returning players load data from the browser cache

Higher stripping levels can remove code that is only reached through reflection, which breaks some serializers and plugins. Use a link.xml file to preserve what those need, and test thoroughly after each change.

Trim the code and packages

  • Remove unused packages. Open the Package Manager and remove anything the game does not use. Some packages pull in engine modules that stripping cannot remove.
  • Audit plugins. Third-party SDKs built for mobile often include code or native libraries that do nothing on the web. Wrap platform-specific code in conditional compilation.
  • Check heavy dependencies. Large JSON or networking libraries can be swapped for lighter alternatives or Unity's built-in options.
  • Avoid threads. C# threading is not available to user code on the Web platform in the way it is on desktop. Code that relies on worker threads or blocking calls must be reworked for the main thread or coroutines.

Shrink the assets

Textures

Textures are almost always the biggest category. Set a web-specific maximum size override and lower it for anything that never fills the screen. Use GPU-compressed formats: desktop browsers typically support DXT/BC formats, while mobile browsers generally need ASTC or ETC2. Check which formats your Unity version can target for web builds and whether it can include more than one. Crunch compression reduces download size further at some cost in quality and build time.

Audio

Use compressed audio, set long music tracks to stream or load in the background, and reduce sample rate for effects where it is not noticeable. Duplicate sounds and unused takes often hide in older projects.

Meshes and animation

Enable mesh compression, remove unused vertex channels, and apply animation compression with reduced keyframes. Delete unused animation clips from import settings.

Shaders

Shader variants can multiply quietly, especially in render pipelines with many features enabled. Turn off pipeline features you do not use, strip unused variants, and keep the list of always-included shaders short.

Load content on demand

A single web build downloads everything referenced by the scenes in the build before the game starts. Anything in a Resources folder is included whether it is used or not. To get players in quickly:

  1. Move content out of Resources folders unless it is genuinely needed at start.
  2. Put later levels, extra characters and optional content into Addressables or AssetBundles.
  3. Host those bundles on a CDN and load them when the player approaches them.
  4. Keep the first scene light: a small loader, the menu and the first level.
  5. Show progress while bundles download, and cache them so repeat visits are quick.

Serve the build correctly

Compressed Unity builds need the server to send the right headers. Brotli or gzip files must be served with a matching Content-Encoding header, and WebAssembly files with the application/wasm content type. Without that, the browser either fails to load the build or you have to fall back to slower decompression in JavaScript.

Note that browsers only accept Brotli content encoding over HTTPS. Put the build behind a CDN, use content hashes in filenames, and set long cache lifetimes on those files. More general techniques are in how to make a browser game load fast.

Memory and mobile browsers

Unity 6 supports mobile browsers for the Web platform, but phones have far less memory available to a tab. Keep the heap small by unloading unused assets between levels, avoiding large allocations at runtime and lowering texture sizes for mobile. Test on real devices, including iPhones, where a tab that uses too much memory may be reloaded by the browser.

Touch input, screen orientation, on-screen keyboards and audio that only starts after a user gesture all need attention when a game moves from desktop to mobile web.

Unity web optimisation checklist

  • Baseline size and load time recorded from a release build.
  • Editor log build report reviewed; largest assets addressed.
  • Brotli compression on, decompression fallback off, server headers configured.
  • Stripping and Strip Engine Code enabled, with link.xml where needed.
  • Development build off; exception support minimised.
  • Unused packages and platform-specific plugins removed or excluded.
  • Texture size overrides and compressed formats set for web.
  • Audio compressed; music streamed or deferred.
  • Shader variants stripped; unused pipeline features disabled.
  • Later content moved to Addressables or AssetBundles on a CDN.
  • Tested on desktop and mobile browsers, including memory behaviour.

When Unity is not the right web tool

Even a well-optimised Unity web build has an engine runtime to download. For playable ads or ultra-light campaign games, a web-native framework is usually a better fit; see Phaser vs PixiJS vs Three.js vs Babylon.js. For portals, read publishing on web portals to check how your build compares with their guidance.

When to bring in a studio

Unity web ports often hit hard problems late: threading code that will not run, plugins with no web support, or memory crashes on phones. A short technical audit up front catches these early. Our browser game development services include Unity web ports, and our porting and co-development team handles broader multi-platform work.

FAQ

Does Unity still support WebGL?

Yes. In Unity 6 the target is called the Web platform and builds still use WebGL 2, with a WebGPU option marked experimental at the time of writing. Unity 6 also officially supports mobile browsers for web builds.

Why does my Unity web build fail to load on my server?

The most common cause is missing server headers for compressed files. Brotli or gzip build files need a matching Content-Encoding header, and WebAssembly files need the application/wasm content type. Brotli also requires HTTPS.

Can I convert my Unity game into a playable ad?

A full Unity web build is normally far too large for ad network limits. Most teams rebuild the key mechanic in lightweight HTML5 code using the game's art, which keeps the package small and gives control over network requirements.

Planning something like this?

See how paxl.co handles browser & webgl games, or tell us about your project and we will reply within two working days.

Keep reading