'Unity WebGL unsupported MIME type

I'm starting a new blank project for webgl. I'm using Unity 2020.3.26f1 (LTS). When I launch the project on my wamp server I get this error:

wasm streaming compile failed: TypeError: WebAssembly: Response has unsupported MIME type 'application/x-gzip' expected 'application/wasm'
falling back to ArrayBuffer instantiation

This doesn't happen when I press the build and run button. Is there some server configuration that I missed or it is a Unity bug?



Solution 1:[1]

Not sure if this is still something you're working on, but I've been going through the same hurdles as you (same Unity version too).

For these Publishing Settings:

enter image description here

I managed to get mine working by adding this to a .htaccess file:

# enable cached data to be read
Header set Content-Security-Policy "worker-src 'self' blob:; script-src 'self' blob:;"

<IfModule mod_mime.c>
    # compression disabled?
    AddType application/wasm .wasm
    AddOutputFilterByType DEFLATE application/wasm

    # support for compressionfallback option
    AddEncoding gzip .unityweb

    # Gzip support
    <Files *.js.gz>
        AddType application/javascript .gz
        AddEncoding gzip .gz
        ForceType application/javascript
    </Files>
    <Files *.wasm.gz>
        AddType "application/wasm" .gz
        AddEncoding gzip .gz
    </Files>

    <Files *.data.gz>
        AddType "application/octet-stream" .gz
        AddEncoding gzip .gz
    </Files>

    # brotli support
    <Files *.js.br>
        AddType "text/javascript" .br
        AddEncoding br .br
    </Files>

    <Files *.wasm.br>
        AddType "application/wasm" .br
        AddEncoding br .br
    </Files>

    <Files *.data.br>
        AddType "application/octet-stream" .br
        AddEncoding br .br
    </Files>
</IfModule>

I think your question specifically relates to the <Files *.wasm.gz> section, though I could be wrong. I ran into a couple more issues after sorting the wasm MIME type one so I figured I'd paste in the full file content.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 exafred