We are using Firebase hosting to host a Unity 2020 WebGL project. By default, a Unity 2020.3 (LTS) WebGL build will run successfully when served from a local Unity Editor, but fails to run at all when deployed to Firebase Hosting. I appreciate that this question straddles a line between Firebase and Unity, so I'm going to attempt to ask the most specific questions possible in the hope somebody can clarify. There are no google hits which imply anyone is successfully hosting a Firebase Unity 2020 WebGL project using Firebase hosting (which seems like it should be happening) and information is limited, e.g. this unanswered question here which I'll try to be more specific than:
On migration to Unity 2020.3 LTS, using the default "GZip Compression", a build deployed to Firebase Hosting (via the minimum friction path of copying the build output folder to your public folder) will no longer load. Viewing the chrome debug console reveals that it has crashed on startup with:
/WebGLMacRelease/Bui…e.framework.js.gz:1 Uncaught SyntaxError: Invalid or unexpected token
I suspect this is because hosting configuration is not set up correctly, so I attempted to add the headers documented at this link to the hosting section of firebase.json.
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
},
"headers": [
{
"source": "**/*.gz",
"headers": [
{
"key": "Content-Encoding",
"value": "gzip"
}
]
}
]
}
However, this doesn't seem to stop the problem, and I did not manage to write any version of firebase.json (including permutations of wildcards, and adding Content-Type headers) which resulted in a successfully loading project.
It seems that if we only care about modern desktop browsers (specifically, Safari and Chromium-derivatives like Chrome and the new Edge) the best thing to do is to disable Unity compression altogether, and let firebase hosting perform the gzip (and potentially Brotli) compression for us? I can confirm that this works. So, questions:
(1) Is it by design that I can't make a firebase.json that adds the correct extensions? Does anybody have an example that works?
(2) Is it reasonable best-practice if using Firebase hosting, and assuming "modern" desktop browsers just to disable Unity's Gzip compression and let Firebase hosting handle the compression, with the browser performing browser-native decompression?