About the cache mechanism of wasm.unityweb.

Hello, I have a question, I exported the game to the WebGL platform and opened the game using the WebView for Android. I found that the file wasm.unityweb has cache if it's within 5MB, but no cache if it's more than 5MB and the file wasm.unityweb will be re-downloaded every time I start the game. But the file data.unityweb is about 10MB, but it has cached all the time, is it because the cache of data.unityweb is using IndexedDB while the cahce of wasm.unityweb is using LocalStorage? I checked the limit of LocalStorage is about 5MB, is there any way to make wasm.unityweb have a cache even if it is more than 5MB?

The version of Unity I'm using is 2021.3.20f1.

@jukka_j @diverges_unity @brendanduncan_u3d @unityruba
Does anyone know anything about this?

Does anyone else know about this problem?

Earlier versions of Unity utilize IndexedDB to implement caching of .wasm and .data files if "Data Caching" option is enabled. Later versions (off the top of my head, 2022.1 and newer, although don't quote me on that, my memory might be failing) updated to utilize the Cache API instead, which provides better performance than IndexedDB.

Local Storage API is never used to cache downloads. Unity does not utilize Local Storage for any purpose.

1 Like


Hi, @jukka_j thanks for your response. But what I want to ask is why wasm.unityweb seems to re-download every time the cache goes over 5MB(I've actually measured 5.2MB and it will cache, but 5.4MB cahce will fail), but data.unityweb doesn't? I can easily reproduce this problem in Android's Webview.

That sounds like a limitation of web browsers that they decide that too large files should not be cached. The "Enable Data Caching" option in Unity is designed to fix that browser issue.


Hi, @jukka_j thanks for your response. But I do have Data Caching enabled. data.unityweb is currently cached for sizes over 10MB, but wasm.unityweb is not cached for sizes as small as 5.4MB.

That is surprising. Any chance you'd have a build hosted somewhere to double check?

Seeing the same issue with Data Caching turned on. WASM file with 9MB not being cached on Android webivew despite caching properly outside (when tested in Chrome).

@jukka_j ,
Is this a known issue?
Is there maybe an option to split the WASM file? Perhaps using https://emscripten.org/docs/optimizing/Module-Splitting.html?

Data Caching should definitely cache the Wasm file no matter how large it is. I wonder if there is some kind of issue with Android WebView's management of IndexedDB and Cache APIs. If you have a standalone bug case, reporting that would be welcome. If it turns out to be a Chrome issue, we can forward it to the Google bug tracker.

Unfortunately Wasm splitting is not a turnkey solution that could be adopted for this type of scenario.

Thanks for the reply. Will work on opening a bug case.

1 Like

Hi all, I'm currently working with plenty webGL builds and I can confirm that in every one of them the *.data file is always correctly cached (with size like 100 MB sometimes) and the *.wasm file, which is always smaller in size than the *.data file, is never cached and therefore downloaded everytime. This slows down the loading of certain of our applications by a considerably amount.

Did you see this on multiple devices (web and mobile web)?

Hi, found the thread after posting my own problem with the same roots.
https://discussions.unity.com/t/938101
There I wrote in more detail the reasons and an idea for a solution, but I still need to figure out the javascript side

1 Like

Hi, we also encountered caching problems and had to check the client loader implementation.
There is a WebAssemblyStore defined, it is created in the UnityCache, but it seems to be never used not in the loader nor framework

(Unity 2021.3.23f1 WebGL Build)

1 Like

A bug report here would be perfect, because as Jukka mentioned before, if it's a Chrome issue, we can forward the project that reproduces this problem to them.