Enable Brotli Compression for Webgl Hosted on Firebase Hosting

Hi!

I’ve been hosting my Unity Webgl project on Firebase Hosting for quite some time due to it’s simple command line deployment process.

However, I am just working on improving the load speed and I’ve noticed I keep getting the console log when starting the application.

1,1,8,0 - Loading Performance.loader.js:1 You can reduce startup time if you configure your web server to add "Content-Encoding: br" response header when serving "Build/1,1,8,0 - Loading Performance.framework.js.unityweb" file.

I have been searching everywhere on how to properly set up brotli with Firebase Hosting but have not yet seemed to find a way that works. I’ve tried to adjust the firebase.json file in the hosting deployment folder as follows, but it does not seem to actually work:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "headers": [
      {
        "source": "**/*.unityweb",
        "headers": [
          {
            "key": "Content-Encoding",
            "value": "br"
          },
          {
            "key": "Content-Type",
            "value": "application/octet-stream"
          }
        ]
      }
    ]
  }
}

Otherwise I may have to look into hosting my production build on AWS instead where brotli is easier to setup, however I’ve struggled connecting my custom domain there…

I hope anyone has a solution to this!

Firebase does compression automatically since 2020. You can refer this post: New for Firebase Hosting: request logging, Brotli compression, and internationalization

So, you will have to Disable the compression from Unity side. I had the same problem and it worked for me.