Search Unity

Question Smallest possible WebGL build size?

Discussion in 'Web' started by AdamandEveStudios, May 5, 2023.

  1. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    20
    Has anyone ever tested this? For arguments sake lets say there are zero assets in the project. One simple scene being built with nothing except a camera and directional light. With the highest compression and stripping what would the smallest possible webgl size be?

    Have optimized every single asset dowe to the kilobyte but am left with huge UnityEngine DLLs clogging up the build. Current build size is 18MB and System DLLs, Script DLLs, and UnityEngine take about 12MB.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Be sure to check RELEASE builds only!

    My last WebGL build was less than 10 MB and ~5 MB is supposedly (read that in some other thread) about as low as you can go - but this changes between Unity versions.

    UPDATE: I investigated minimum WebGL build sizes here (1.8 MB for Legacy, 3.5 MB for URP). That thread contains a lot of other useful info as well.
     
    Last edited: Jun 18, 2023
    1000Nettles likes this.
  3. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    20
    thank you for the reply. ~5 MB is definitely the goal. Good to know that this is actually achievable. By release mode do you mean not developer mode? I rarely use developer mode when building to webgl.

    In terms of Unity versions I just made the fatal error of upgrading to 2022.2.17 and now all my webgl builds hang permanently on "linking build.js" :(
     
  4. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    The smallest build I achieved was 2.47MB with Unity 2020.3 with builtin render pipeline and brotli compression targeting webgl1. This build includes a simple test scene with some falling blocks and I also didn't start manually stripping out builtin packages, so I think you can go een a bit lower than that. You can test the build yourself here: https://deml.io/experiments/unity-webgl/2020.3.46f1-minsize-webgl1
    And that is the repo to see the exact setup I'm using: https://github.com/JohannesDeml/UnityWebGL-LoadingTest
    To get the settings for the min size build, just build the project with minsize, then it will apply all settings that are used for that to the project settings :)

    upload_2023-5-5_19-25-48.png
     
    LilGames, Wokou-Dev and Unifikation like this.
  5. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    20
    Wow. This is exactly what I needed. Truly amazing info you've gathered all into one nice spot. I will use this and report back!

    In terms of build size for webgl 2 - 2021.2.19f1 is the winner? I will be porting over my project to a stable version as 2022 is basically unusable
     
  6. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Glad you find it useful!
    Yes, that would be the winner, but tbh I would recommend to go with Unity 2021.3.x, since that is the LTS version, and the difference in build size is not that big. If you want to see and test all the builds I did over the years, you can find them here: https://deml.io/experiments/unity-webgl/
    Note however, that the unity template and functionality grew a bit over time, so older build versions might have less KB. The list of builds on the github page is a fair comparison, since they all use the same template.
     
    Wokou-Dev and Unifikation like this.
  7. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Regarding release, check the player settings. You want to tick all the release buttons, disable exceptions and all that.
    However for development you should definitely make debug/dev builds because they can be done in 2 min. vs 20 for a release build. Check what the build time is for your project in dev vs release builds, and do each build twice so you can see the truly incremental build speedups.

    As to upgrading and running into troubles, my experience is that you are most likely have to debug the issue. It’s comparatively rare that it’s a specific Unity issue and waiting will get it fixed. In any case, try 2022.2.0 and see if it works there. If it does you can work your way up to the highest version that still builds your project, then check the changelogs for the next version for any hints regarding what may trigger the issue.
     
  8. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    20
    this is an absolute gold mine of information. Should be pinned at the top. TY for making this