Game porting · Unity · Web

Port your Unity game to the browser: an optimized WebGL build or a Defold rewrite

There are two honest ways to port a Unity game to the browser. You can keep the game in Unity and ship an optimized Web build, the target that older Unity versions call WebGL. Or you can rewrite the game in Defold when the Unity build stays too heavy for your target, for example a web portal with a strict download limit or players on older phones. This page explains both paths, how we choose between them and what you get at the end. For the general process from audit to release, read our step by step guide to web game ports.

· Service guide

By

Czytaj wersję polską →

A Unity mobile game running in a desktop browser and a phone browser

Can Unity export to HTML5?

Yes. Unity has a Web build target, called WebGL in older versions. Unity compiles your C# code to WebAssembly, and the game renders with WebGL 2. The result is an HTML page with a loader and compressed build files that you can host on any web server.

Unity 6 added official support for mobile browsers: iOS Safari 15 and newer and Chrome 58 and newer on Android. On desktop you need a browser with WebGL 2 and 64-bit WebAssembly. So the export itself is rarely the problem. The hard part is a build that is small, stable and fast enough for real players.

Path 1: ship an optimized Unity WebGL build

This path keeps your code, scenes and tools. It fits when the game is light enough for the place where you publish it, or when you can make it light enough.

  • Build size. Release builds without development options, code optimized for disk size, managed code stripping and Brotli compression on a server that serves it correctly. Unity lists these settings in its guide to optimizing Web builds.
  • Assets and loading. Texture compression that the target devices support, lighter audio and content that loads later with Addressables or asset bundles, so players reach the first scene quickly.
  • Memory. A browser tab gets far less memory than a native app, and a crash during loading is a common problem on phones. We profile the heap and the largest textures on real devices. Unity itself recommends iOS Safari 18.2 or newer because of its higher memory limit.
  • Plugins and SDKs. Native Android and iOS plugins do not run in the browser. Ads, analytics, saves, purchases and login need web versions, usually JavaScript plugins (.jslib) and the SDK of the portal you publish on.
  • Input and audio. Mouse and keyboard controls next to touch, and audio that starts after the first tap or click, because browsers block sound before the player interacts with the page.
  • Portal requirements. Web portals publish their own rules. CrazyGames, for example, asks for an initial download of 50 MB or less in a basic implementation. Poki has its own developer documentation for the SDK, testing and onboarding.

Checklist: reduce the Unity WebGL build size

  1. Turn off Development Build for the release build.
  2. Set Code Optimization to Disk Size with LTO. Unity also offers Maximum Size Reduction, which you should test for performance.
  3. Set Managed Stripping Level to High and keep a link.xml file for code that runs through reflection.
  4. Turn on Strip Engine Code.
  5. Use Brotli compression and serve the game over HTTPS, because Chrome and Firefox support Brotli natively only there.
  6. Compress textures with formats the target devices support and lower their resolution where players will not notice.
  7. Move content the first level does not need into Addressables.
  8. Remove unused packages and plugins, then check the build report for the largest assets.

Unity collects more tips for phones in its page on optimizing the Web platform for mobile.

Path 2: rewrite the game in Defold

Sometimes the Unity build stays too large or too slow after all the optimization. We see this most often with 2D and light 3D games that must open in a few seconds on older phones or pass a strict portal limit.

In that case we rebuild the runtime in Defold and keep what players see: the design, the art, the audio, the levels and the balance data. The C# gameplay code is rewritten in Lua. Defold has a small engine, you can leave out the engine features a game does not use, and one project builds for the web, iOS, Android and desktop. We describe the steps in our guide to porting a Unity game to Defold.

Our team includes experienced Unity and C# developers, and we have moved mobile games of well-known brands from Unity to Defold for the web. That helps us read the original project quickly and keep the game feel the same.

How we choose between the two paths

We start with a short audit of the project and a test build in a real browser. Then we compare the result with your target.

  • Stay in Unity when the build fits the portal limits after optimization, the game relies on 3D or Unity features that are hard to rebuild, or your team will keep developing it in Unity.
  • Move to Defold when the game is 2D or light 3D, the first download must be small, older phones matter, or you want one lighter project for web and mobile.
  • Look at the business side too. Where you will publish, how players will find the game and how it will earn money. Our web porting service page covers the wider process for Unity, Godot and Construct games.

Before production starts, you get a written recommendation with the risks of each path.

Unity games already in the browser

Subway Surfers is a Unity game, and its official web version runs on Poki with arrow keys on desktop and swipes on phones. More ports are in our examples of mobile games ported to the browser.

How to put a Unity game on your website

A Unity Web build is a folder with an HTML file, a loader script and the compressed build files. You can host it on your own server or a CDN and embed it in a page with an iframe. The server must send the right Content-Encoding header for Brotli or gzip files, as Unity explains in its deployment guide. Use HTTPS, and test the page on a phone before you share the link.

What you get

  • An audit with the recommended path and the main risks.
  • A first test build in the browser early in the project.
  • A release build tuned for your website or target portal, with the portal SDK in place.
  • Tests on desktop and mobile browsers, older phones included.
  • The full source project and build instructions.

Work with Codeward

Codeward is a game studio from Kraków with many client projects behind it. We port games to the browser from Unity, Godot, Construct and other engines. Send us a link to a build or a short description of your Unity game, and we will tell you which path makes sense for it.

FAQ

Questions about porting Unity games to the browser

Can you port my Unity mobile game to WebGL?

Yes. We either optimize the Unity Web (WebGL) build of your game or rewrite the game in Defold when the Unity build is too heavy for the target. We choose after a short audit and a test build in the browser.

Can Unity export to HTML5?

Yes. The Unity Web build target, called WebGL in older versions, produces an HTML page with WebAssembly code and WebGL 2 rendering. It runs in current desktop browsers and, since Unity 6, in supported mobile browsers.

How do I reduce the size of a Unity WebGL build?

Build without development options, optimize code for disk size, set managed code stripping to High and use Brotli compression. Compress textures, load content the first level does not need later, and check the build report for the largest assets.

Will my Unity WebGL game run on phones?

It can. Unity 6 supports iOS Safari 15 and newer and Chrome 58 and newer on Android. Memory is the main limit, so test on older phones and keep the heap and textures small.

What happens to native plugins and SDKs?

Android and iOS plugins do not work in the browser. We replace them with web versions, usually JavaScript plugins and the SDK of the portal you publish on, for ads, analytics, saves and purchases.

When is a Defold rewrite better than a Unity WebGL build?

When the game is 2D or light 3D, the first download must be very small, older phones are important or the Unity build stays too heavy after optimization. Defold is designed for small and fast builds, and one project covers web and mobile.

Can you prepare the game for Poki or CrazyGames?

Yes. We prepare the build for the portal you choose: the download limits, the SDK for ads and gameplay events, and tests on the devices its players use. Each portal reviews games on its own terms, so the final decision to publish is theirs.

How long does it take to port a Unity game to the browser?

It depends on the size of the game, the state of the code, the plugins and the chosen path. An optimized Unity build usually takes less time than a rewrite. We give a timeline after the audit and the first browser test.

Do I keep the source code?

Yes. You get the full source project and the build instructions, whether the game stays in Unity or moves to Defold.

About the author

Paweł Jarosz is a game developer in Kraków with over 13 years of experience, the founder of Codeward and Community & Content Manager at the Defold Foundation. He builds games and shares practical tutorials on the Unfolding Gamedev YouTube channel.

Want your Unity game in the browser?

Codeward is a game development studio in Kraków. We port Unity games to the web as optimized WebGL builds or as Defold rewrites. Send us a build or a short description and we will reply as soon as we can.

What should you send us?

  • The Unity version and the target platforms.
  • A link to a build or a short video of the game.
  • The plugins and SDKs the game uses.
  • Where you want to publish: your site, Poki, CrazyGames or another portal.