0

Site is hosted on a Ubuntu 18 server Managed by runcloud.io PHP 7.4 runcloud's nginx default config.

We have a webgl build deployed on our staging server, and unable to get it to load without throwing console errors:

You can reduce your startup time if you configure your web server to host .unityweb files using gzip compression.

wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

falling back to ArrayBuffer instantiation

I have create the following nginx config file:

location ~ .(wasm)$ {
    add_header Content-Encoding gzip;
    add_header Content-Type application/wasm;
}

location ~ .(unityweb)$ {
    add_header Content-Encoding gzip;
    add_header Content-Type application/octet-stream;
}

location ~ .(data.unityweb)$ {
    add_header Content-Encoding gzip;
    add_header Content-Type application/octet-stream;
}

location ~ .(wasm.framework.unityweb)$ {
    add_header Content-Encoding gzip;
    add_header Content-Type application/octet-stream;
}

include /etc/nginx-rc/mime.types;
types {
    application/wasm wasm;
}
default_type application/octet-stream;
    
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types application/wasm application/octet-stream text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
Philip Smith
  • 327
  • 4
  • 17
  • Did you finally solve it? I'm stuck too. – Olivier Pons May 16 '21 at 10:55
  • @OlivierPons yes. It turns out that you have to either disable compression in Unity and allow the web server to compress it, or leave compression enabled in Unity and disable server gzip / brotli. The problem was that Unity + server was creating "double compression" and the browser could not understand the content. – Philip Smith Oct 02 '21 at 02:14

1 Answers1

1

I managed to host a Unity/WelGL app on a nginx server changing parameters of my Unity "Project Settings":

In "Player" tab, open "Publishing Settings":

  • Compression Format: Gzip
  • Decompression Fallback: ON

Found the solution on the Unity WebGL documentation. This is avoiding the error message.

I did not had to change my nginx configuration files.

mmerle
  • 451
  • 4
  • 10