WebGL error while running: HTTP Response Header "Content-Type" configured incorrectly on the server for file Build/xxx.wasm.gz

Hi,

I have created a WebGL build of my game, and hosted it on my own server.

It does run and works fine, however it shows a yellow dialog box saying:

HTTP Response Header “Content-Type” configured incorrectly on the server for file Build/PopSquaresWeb.wasm.gz , should be “application/wasm”. Startup time performance will suffer

In order to get it running I created a .htaccess file below as specified here: Unity - Manual: Set up your Apache server configuration for Web builds

Does anyone have any suggestions as to how to remove this error?

thanks

Nalin

# NOTE: "mod_mime" Apache module must be enabled for this configuration to work.
<IfModule mod_mime.c>

# The following lines are required for builds without decompression fallback, compressed with gzip
RemoveType .gz
AddEncoding gzip .gz
AddType application/gzip .data.gz # The correct MIME type here would be application/octet-stream, but due to Safari bug https://bugs.webkit.org/show_bug.cgi?id=247421, it's preferable to use MIME Type application/gzip instead.
AddType application/wasm .wasm.gz
AddType application/javascript .js.gz
AddType application/octet-stream .symbols.json.gz

# The following lines are required for builds without decompression fallback, compressed with Brotli
RemoveType .br
RemoveLanguage .br
AddEncoding br .br
AddType application/octet-stream .data.br
AddType application/wasm .wasm.br
AddType application/javascript .js.br
AddType application/octet-stream .symbols.json.br

# The following line improves loading performance for uncompressed builds
AddType application/wasm .wasm

</IfModule>

Hi!

What server are you using for hosting? Not all web servers support the .htaccess file.

Also, theres been a lot of talk on this and the derrived results seem to be that it changed a while back, and now the default seems to be

AddType application/wasm .wasm
AddEncoding gzip .unityweb

RewriteEngine on

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<IfModule mod_mime.c>

 <FilesMatch "[^.]+\.unityweb$">
  Header set Content-Encoding "gzip"
</FilesMatch>

 
 <FilesMatch "[^.]+\.gz$">
  Header set Content-Type "application/gzip"
  Header set Content-Encoding "gzip"
</FilesMatch>

<FilesMatch "[^.]+\.data\.gz$">
  Header set Content-Type "application/octet-stream"
  Header set Content-Encoding "gzip"
</FilesMatch>
 
<FilesMatch "[^.]+\.js\.gz$">
  Header set Content-Type "application/javascript"
  Header set Content-Encoding "gzip"
</FilesMatch>
 
<FilesMatch "[^.]+\.wasm\.gz$">
  Header set Content-Type "application/wasm"
  Header set Content-Encoding "gzip"
</FilesMatch>
 
 <FilesMatch "[^.]+\.wasm$">
  Header set Content-Encoding "gzip"
  Header set Content-Type "application/wasm"
</FilesMatch>

<FilesMatch "[^.]+\.data\.br$">
  Header set Content-Type "application/octet-stream"
  Header set Content-Encoding "br"
</FilesMatch>
 
<FilesMatch "[^.]+\.js\.br$">
  Header set Content-Type "application/javascript"
  Header set Content-Encoding "br"
</FilesMatch>
 
<FilesMatch "[^.]+\.wasm\.br$">
  Header set Content-Type "application/wasm"
  Header set Content-Encoding "br"
</FilesMatch>


</IfModule>

Thanks so much @bugfinders

This now works with gz compression with no dialogs.

However it does break the uncompressed build

WebAssembly streaming compilation failed! This can happen for example if "Content-Encoding" HTTP header is incorrectly enabled on the server for file Build/PopSquaresWeb.wasm, but the file is not pre-compressed on disk (or vice versa). Check the Network tab in browser Devtools to debug server header configuration.

and the Brotli compressed build

Unable to parse Build/PopSquaresWeb.Brotli.framework.js.br! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header "Content-Encoding: br" present. Check browser Console and Devtools Network tab to debug.

I can live with this so thank you so much :slight_smile:

Nalin

@MarcelPursche

Hostinger.

I updated the reply below and now I have it working with .gz with no dialogs :slight_smile:

This line looks suspicious to me and is likely causing the issue:

 <FilesMatch "[^.]+\.wasm$">
  Header set Content-Encoding "gzip"
  Header set Content-Type "application/wasm"
</FilesMatch>

The content encoding shouldn’t be “gzip” for files just ending with .wasm.

see, no offence @MarcelPursche this is why unity is such a pain in the fluff for webgl people, it changes, a while back this was essential, or it didnt work.. we have to force webservers to send your data in a way that isnt natural, when it should be natural..

anything that is .gz should be just gzip, anything that is wasm should be wasm, why is it always changing and always complicated?

Interestingly i use brotti, and mine are fine. Are you sure you copied the whole thing?

Thanks @MarcelPursche

What should I set Content-Encoding to instead here?

BTW might be an idea to update the docs…

Yeah @bugfinders I copied the whole thing, though I will test again

The header shouldn’t be set for uncompressed content. So I would just remove that line.

So far the best and easiest solution i found :slight_smile: