How to reduce HTML5 package size?

I am using UE 4.6 and developing a HTML5 game. I want the final package size to be as small as possible but right now, it seams that a lot of unnecessary stuff gets packed into it.

I work with Blueprints. The size of the content folder, including all assets, is 18.5 MB and the resulting HTML5 package is about 74 MB

23347-package-sizes.jpg

I researched some possibilities to minimise the size. Here is what I did:

  • project has no starter content

  • used assets do not reference to assets in the engine folder (except for MatineeCam) (checked with the Reference Viewer on my map)

  • packaging settings are set to ā€œFull Rebuildā€, ā€œFull Distributionā€ and ā€œShippingā€

  • excluded " /Engine/MobileResources" from content directories

  • disabled Slate

  • disabled plugins in the editor and checked in the uproject file:

    ā€œPluginsā€: [
    {
    ā€œNameā€: ā€œAndroidDeviceProfileSelectorā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œAppleMoviePlayerā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œAvfMediaā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œBlankPluginā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œCableComponentā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œCharacterAIā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œCustomMeshComponentā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œEpicSurveyā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œExampleDeviceProfileSelectorā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œIOSDeviceProfileSelectorā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œMacGraphicsSwitchingā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œMediaPlayerEditorā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œMessagingDebuggerā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œOculusRiftā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œPerforceSourceControlā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œScriptGeneratorPluginā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œScriptPluginā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œSlateRemoteā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œSpeedTreeImporterā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œUdpMessagingā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œUObjectPluginā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œWmfMediaā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œWindowsMoviePlayerā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œXCodeSourceCodeAccessā€,
    ā€œEnabledā€: false
    },
    {
    ā€œNameā€: ā€œSubversionSourceControlā€,
    ā€œEnabledā€: false
    }

  • modified .target.cs

    public override void SetupGlobalEnvironment(
    TargetInfo Target,
    ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,
    ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration
    )
    {
    UEBuildConfiguration.bCompileFreeType = false;
    UEBuildConfiguration.bCompilePhysXVehicle = false;
    UEBuildConfiguration.bCompileSpeedTree = false;
    UEBuildConfiguration.bCompileRecast = false;
    UEBuildConfiguration.bCompileAPEX = false;
    UEBuildConfiguration.bCompileLeanAndMeanUE = true;
    UEBuildConfiguration.bCompileICU = true;
    UEBuildConfiguration.bCompilePhysX = false;
    UEBuildConfiguration.bBuildEditor = false;
    UEBuildConfiguration.bBuildWithEditorOnlyData = false;
    UEBuildConfiguration.bBuildDeveloperTools = false;
    UEBuildConfiguration.bCompileBox2D = false;
    UEBuildConfiguration.bCompileSimplygon = false;
    UEBuildConfiguration.bCompileSteamOSS = false;
    UEBuildConfiguration.bCompileMcpOSS = false;
    UEBuildConfiguration.bWithServerCode = false;
    UEBuildConfiguration.bCompileWithPluginSupport = false;
    // this seams to not affect the package size; only works for C++ code?
    UEBuildConfiguration.bCompileForSize = true;
    }

The thing is, that even though I disabled all plugins etc. the resulting .data.js file still references these assets, which I am definitively not using. Even the standard ā€œEntry.umapā€ is listed but this map doesnā€™t even exist. Here is a small excerpt of these unwanted files:

The TappyChicken demosā€™ .data.js loads way less assets than mine.
What can I do to get rid of unnecessary stuff? Maybe I am just missing a detail. Any comment will help! Thanks

Update

I am now using UE 4.6.1, started a completely fresh project and implemented everything in C++. Unfortunately this changed nothing with the package size. I did a full memreport ([Debugging and Optimizing Memory][4]) but had no luck in optimizing. I really hope this will get better.

1 Like

I have the same problem. You have more options to packaging project with UnrealFrontend, but I have not been able to improve the result.
I continue investigating for this problem, if i have got lucky, Iā€™ll publish my results in this post.

I think Iā€™m collecting (bookmarking) this kind of package-size questions that are never answered. Is very sad. The only thing that could take me away from making mobile games with UE4 is the ridiculous big file size.

To shrink the size of a HTML5 deployment I recommend you to pre-gzip the content, I was able to get the final size to about 15 MB for the engine and the game for an HTML project (just select the big blue button https://ikea.pr/puertorico/desktop/es_pr/catalogos/categoria/escenario/detalle/apartamento-de-verano_PR).

Once you have gzipped your content (apache example: Serving pre-compressed files using Apache) you have two options, always serve gzip or serving both and if the client is able to read gzip content serving the gzipped version. Deciding if the client can handle gzip is easy, just create a .js file, gzip it to .js.gzip (gzip with the -9 option which indicates best compression rates) and try to load it. If you add a variable in that file like var enable_gzip = true; and your client can load that file the enable_gzip will be defined, if not enable_gzip will be undefined and you can change the extension you request from the server.

From you file sizes the engine should go under 10 MB and the game around 6 MB.

Thanks for your reply and the examples, Moss. I looked at your example and it turns out that I downloaded around 37 MB (CloudStore.data.jgz alone is already 27.5 MB large).
I already transfer my data compressed (forgot to mention that; currently using deflate but I am going to check out gzip), however I forgot to include the *.mem file in the compression filter which now saved me another 6.5 MB.

Afaik transferring the data compressed is only good for the downloading purpose but after all the users browser still has to load the full uncompressed files in the memory and needs to deal with them - my actual question is how to reduce the package size in the first place because there really is a lot of unnecessary stuff in the package.

Thanks anyway. This is helpful for others, too.

Thatā€™s the same problem I have with android non-source project. Is not about game content compression, is the whole engine is included in the package and the smallest .apk size I could achieve is 36MB with only 2MB of my actual game content.
If Epic wants to continuew advertising that UE4 produce games for android and HTML5 they need to do something to reduce engine package size. Also this solution has to be easy for us, because to reduce my package size from 54MB to 36MB i had to do a lot of tricks, some of them a bit dirty.

HTML5 is still experimental so it will get better for sure :smiley:

Without pre-compression the browser was not able to even download the build and crashed with Out of Memory errors.

I guess the only way to get rid of all those plugins and additional is really using a source release and not compile the plugins. If you disable the plugins for the project from the editor are they getting included too?

You can either delete them from the Engine/Plugins folder (might be tricky). Or set them to be ā€˜Editorā€™ or ā€˜Developerā€™ plugins instead of ā€˜Runtimeā€™ plugins in the .uplugin files.

I have not tried it but that would be the starting point.

I guess the only way to get rid of all those plugins and additional is really using a source release and not compile the plugins.

Do you know how I can achieve that?

If you disable the plugins for the project from the editor are they getting included too?

Yes, I uncheck the plugins in the Plugins Browser (Window ā†’ Plugins) and check if they are disabled in my uproject file, too. Still they get included.

Very good post!! We reduced our project 40 MB with this compresion.
You must to active de mod_deflate module in Apache and add .htaccess with this code on the hosting site:

#LoadModule deflate_module modules/mod_deflate.so

<IfModule mod_deflate.c>

    # Activamos la compresiĆ³n
    SetOutputFilter DEFLATE

    # Indicamos los tipos de contenido a comprimir
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/gml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE data


    # Indicamos las extensiones de los ficheros a comprimir
    <files *.html>
        SetOutputFilter DEFLATE
    </files>
    <files *.xml>
        SetOutputFilter DEFLATE
    </files>
    <files *.gml>
        SetOutputFilter DEFLATE
    </files>
    <files *.json>
        SetOutputFilter DEFLATE
    </files>
    <files *.js>
        SetOutputFilter DEFLATE
    </files>
    <files *.css>
        SetOutputFilter DEFLATE
    </files>
    <files *.data>
        SetOutputFilter DEFLATE
    </files>


</IfModule>

But we need more. Do you know if we can reduce the resolution, qualities or engine escalability settings to package in HTML5?
Do you know how can we compress de .DATA file?
Thanks!!

You can add a HTML5 engine ini file and lower the TEXTURE group sizes for all. Just go into base engine ini file and you copy the TEXTUREGROUP settings over to your HTML5 engine ini file, then just lower the max lod size, I use 1024 or 512 and itā€™s still quite nice. You can also change the filters and tweak them a bit.

Hello there,

after looking into this for my own HTML5 project, I noticed that by default, the plugin configuration in the .uproject file is not allowed to disable default plugins. To fix this, edit Engine/Source/Programs/UnrealBuildTool/System/UProjectInfo.cs in GetEnabledPlugins and replace
List EnabledPlugins = new List(DefaultEnabledPlugins);
with
List EnabledPlugins = new List();
( for me, itā€™s line 313 )

Then recompile while specifying the uproject file, that is using
Engine/Build/BatchFiles/Mac/Build.sh UE4Game HTML5 Shipping /path/to/your.uproject
instead of
Engine/Build/BatchFiles/Mac/Build.sh UE4Game HTML5 Shipping

And voila, only the modules you enabled are compiled and linked into your HTML5 runtime :slight_smile:

Hi, you think I can apply your solution to an android project?
Do i need to know anything about c++?

C# or C++? I can understand simple C++ code but I donā€™t know anything about visual studio. Do I need to install Visual Studio? and re-compile something or It will work with my blueprint only project? Thanks for your patience :slight_smile:

This solution works for any platform. However, you need to know a small amount of C# to actually make that code edit, and re-run the build files.

You will have to compile the engine from source. Here you have a complete tutorial on how to compile the engine from sources.

could you please update you answer for current engine? I canā€™t find this strokes.

Iā€™m having the same problem here, but the UProjectInfo file does not have the same code from this answer. Can anyone update the answer to reflect new changes?

Just a quick note since I was looking for MaxLODSize, it now has itā€™s default values (4096) in Engine/Config/BaseDeviceProfiles.ini

[/Script/Engine.TextureLODSettings] @TextureLODGroups=Group TextureLODGroups=(Group=TEXTUREGROUP_World,MinLODSize=1,MaxLODSize=4096,LODBias=0,MinMagFilter=aniso,MipFilter=point,MipGenSettings=TMGS_SimpleAverage)