Cant run unity webgl build with gzip or brotli compression

Im trying to run webgl build with gzip compression but I only manage to run it with compression format disabled in the player settings. I tried different servers like link:http-server with --gzip option enabled.

http-server --gzip

I also run link:spa-server-gzip .


It gives me this output in the inspector:

As you can see the Content-Encoding is set to gzip but Im getting this error message:

Uncaught SyntaxError: Invalid or unexpected token gzip.framework.js.gz:1 
Uncaught ReferenceError: unityFramework is not defined at HTMLScriptElement.r.onload (gzip.loader.js:1) gzip.loader.js:1 

Why is this not working?

How can I run my unity webgl build with gzip or brotli compression?

Have you check the server configuration?