Search Unity

Question Reducing the size of WebGL build

Discussion in 'Web' started by bawenang, Dec 30, 2022.

  1. bawenang

    bawenang

    Joined:
    Aug 18, 2012
    Posts:
    119
    Hi,

    How do you reduce the size of your build? I need to get it to 25 mb max. Right now, this is the size:
    Screen Shot 2022-12-30 at 23.20.34.png

    Here are what I have done:
    1. Use atlases with power of 2 size (mostly 1024x1024)
    2. Use OGGs for the audio files
    3. Use 90% crunch compression with high quality (anything less seems to reduce the quality and made the game ugly)
    4. Disable any exception and stacktrace
    5. Strip the engine code
    6. Optimize mesh data and strip mipmap (although I don't think that they mattered since my game is 2D)
    7. Disable build compression. The server can't handle Gzip nor Brotli.

    Anything else for me to reduce the build? Any suggestion is most appreciated.

    Thakn you.
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,049
    About point 2. Unity compresses audio on build. If you put in a compressed file Unity will compress it again. Using lossless audio files and then using vorbis in the audio settings (with optimize bitrate) is the best way for audio.
    Also, make sure to use 2021.3 or maybe even 2022.2 for new compression features etc!

    Getting a system in place for gzip or brotli is ideal, because compression, well, compresses

    Also delete all unused packages etc.

    Can't say much more without being in the project. You can check the build logs to see exactly how much data is being used per asset
     
    LaurieAnnis likes this.
  3. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    That's a deal breaker. If you can't serve compressed content, 25MB is (almost) an empty URP build.

    Your only hope is to put everything into 25MB asset bundles and stream it in.
     
  4. bawenang

    bawenang

    Joined:
    Aug 18, 2012
    Posts:
    119
    Hi, sorry for the very late reply. About the audio files, so you are suggesting that I use wav or flac files which are lossless and then set the audio to vorbis or mp3 in the settings? Noted. I didn't know that.

    Thanks.
     
    LaurieAnnis likes this.
  5. bawenang

    bawenang

    Joined:
    Aug 18, 2012
    Posts:
    119
    I asked my client and they increased the limit to 30MB. Which is actually more manageable when I build it with optimization for "size" instead of "speed". With "size", I can get to 28MB but with "speed", it increases to 32MB. And the performance hit is not that noticeable too so I guess it's okay. Thanks.
     
    DevDunk likes this.
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,899
    Just to add to this, this post describes making an absolute min-size WebGL build. Not all settings are applicable as they are "lossy" but you may find some settings worthwhile to strip out a few percent without much headaches.
     
    DevDunk likes this.