http://docs.unity3d.com/Manual/webgl-building.html
http://docs.unity3d.com/Manual/ReducingFilesize.html
https://www.youtube.com/watch?v=gVUgF2ZHveo - AssetBundles
When we compile a WebGL project, it generates 3 folders along with html file.
Compressed
Release
TemplateData
index.html
- Release folder has actual .js files converted from Unity's code.
- Compressed folder has gzipped compressed files of above js files generated by Unity.
If your server is setup properly to use these gzipped files (from compressed folder) rather than actual js files (in Release folder)(our server had been setup properly for this part), than your actual game size that game will load is the size of Compressed folder.
-
Use Automatically Crunche" format for textures with various texture size (512,1024,...) and Compression quality as per needs (this can drastically decrease size of textures,hence game size). This option is available under Advanced tab when you click on any texture in game.
-
Asset bundles: Create Asset bundles (Unity Pro Only) of heavy models/prefabs/textures, even full scene and retrieve these bundles later in game from server when it actually opens up (retrieving will use Unity's WWW api), this can also reduce game size.
I can suggest this tool to directly create asset bundles of heavy models/textures or full scenes without much effort on our side.
Bundle Manager: https://www.assetstore.unity3d.com/en/#!/content/14035
-
Mesh Combiners: Use "Mesh Combiners" to create a Single Mesh of various meshes,this drastically reduce size of Mesh (and indirectly reduces polycount in some cases). Also, by combining various meshes to a single mesh, all textures will also be combined in single atlas, thus, again reducing size of game. This also decreases Draw Calls in game, hence game will be more responsive and playable in WebGL.
I would suggest these assets for Mesh Combining and creating atlases of various textures.
- MeshBaker: https://www.assetstore.unity3d.com/en/#!/content/5017
- Simple Mesh Combine: https://www.assetstore.unity3d.com/en/#!/content/8748
-
Atlas: Pack textures in "Single Atlas" and use "Automatically crunched" or "Compressed" format for this single packed texture.
-
Materials : Use least materials as possible, because more the materials in the game, more the drawcalls, so again, use Mesh Combiners suggested above, to create a single material of many materials.
-
Polycount: 3D Model size indirectly depend upon polycount/tris of that model, so use low poly models, or if you don't have any 3d designer available, don't worry smile i would suggest you Cruncher tool, this allows us to reduce polycount of a model/full 3d environment that too inside unity editor wink and pretty simple to use, no need to use max/maya to reduce polycount.
Moreover, lower the polycount of model,better the performance of game.
Cruncher: https://www.assetstore.unity3d.com/en/#!/content/42948
-
WebGL Streaming: https://www.assetstore.unity3d.com/en/#!/content/3836821 Using this, webgl will compile .data file (textures/models are compacted in this file and file is in Compressed folder) into multiple .data files that are equal to number of scenes in game (like
WebGL.0.datagz
,WebGL.1.datagz
,WebGL.2.datagz
..... ), remove default .data file (Webgl.datagz) from there (with streaming, it will not be used).Size distribution:
Webgl.0.datagz
(Scene1 data file), +Webgl.1.datagz
(Scene2 data file) +Webgl.2.datagz
(Scene3 data file) +.... = Webgl.datagz (data file without using streaming).When game opens, it will only load the first scene of game (
Webgl.0.datagz
), exactly same as in webplayer streaming, thus reducing initial load of game smile All other scenes of game (Webgl.1.datagz
,Webgl.2.datagz
...) will be loaded later when game actually opens up (other.data
files ), you can track in unity either other scenes are loaded or not.