Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question HTTP Response Header "Content-Type" configured incorrectly...

Discussion in 'Web' started by SimRuJ, Dec 3, 2021.

  1. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    Hello everyone,

    I exported my WebGL app (Unity 2021.1.24f1) and it's already on the Tomcat server but whenever the Unity loading screen is shown, there's some type of warning above the logo in a yellow box (with a white border):
    "Build/2.wasm" exists in the export. Is that something I have to change for the export or on the server? What exactly do I have to change? I found this and this but I'm not sure I understand what the message is asking of me or where to add stuff, tbh.
     
    Last edited: Dec 3, 2021
    makaka-org and ina like this.
  2. livium

    livium

    Joined:
    Aug 3, 2018
    Posts:
    27
    same here!
     
  3. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Bump... I have this issue too lol
     
  4. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    I managed to fix it! Add the following to the "web.xml" file:
    Code (CSharp):
    1. <mime-mapping>
    2.     <extension>wasm</extension>
    3.     <mime-type>application/wasm</mime-type>
    4. </mime-mapping>
    You might also need:
    Code (CSharp):
    1. <mime-mapping>
    2.     <extension>data</extension>
    3.     <mime-type>application/octet-stream</mime-type>
    4. </mime-mapping>
    5. <mime-mapping>
    6.     <extension>symbols.json</extension>
    7.     <mime-type>application/octet-stream</mime-type>
    8. </mime-mapping>
     
    GhostTap and Mashimaro7 like this.
  5. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Thanks for your solution! But, where is the web.xml? I can't find it in either my project or my build.
     
    KoosyCrypto and dradb like this.
  6. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    The web.xml is a file on the server/in your server project that calls your Unity WebGL project.
     
    Mashimaro7 likes this.
  7. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Ah, I got it. Sorry, don't know much about WebGL, I'm not running it on a server, it's for a client haha.

    Thanks for the response
     
  8. SharrTZaw

    SharrTZaw

    Joined:
    Mar 30, 2019
    Posts:
    13
    Hello, I am facing the same issue! I can't find any web.xml file in my server folder. What have happen to my hosting? I use wordpress on hostinger server. I want to upload my WebGl to my hostinger server
     
    cortexa and dradb like this.
  9. jayray2000

    jayray2000

    Joined:
    Jan 19, 2014
    Posts:
    2
    Hello, unfortunately I have no real solution for the problem. But you can remove the error message that is displayed. To do this simply disable line 70 and 72 in the WebGL.loader.js file. This works with a development build.

    Code (JavaScript):
    1.       if (typeof message === 'string' && message.indexOf('wasm streaming compile failed') != -1) {
    2.         if (message.toLowerCase().indexOf('mime') != -1) {
    3.         //  showBanner('HTTP Response Header "Content-Type" configured incorrectly on the server for file ' + Module.codeUrl + ' , should be "application/wasm". Startup time performance will suffer.', 'warning');
    4.         } else {
    5.           //showBanner('WebAssembly streaming compilation failed! This can happen for example if "Content-Encoding" HTTP header is incorrectly enabled on the server for file ' + Module.codeUrl + ', but the file is not pre-compressed on disk (or vice versa). Check the Network tab in browser Devtools to debug server header configuration.', 'warning');
    6.         }
    7.       }
    For a normal build delete or comment out the first if statement in WebGL.loader.js.
    it is marked in bold in the code example below:

    function createUnityInstance(e,r,n){function o(e,n){if(!o.aborted&&r.showBanner)return"error"==n&&(o.aborted=!0),r.showBanner(e,n);switch(n){case"error":console.error(e);break;case"warning":console.warn(e);break;default:console.log(e)}}function t(e){var r=e.reason||e.error,n=r?r.toString():e.message||e.reason||"",o=r&&r.stack?r.stack.toString():"";if(o.startsWith(n)&&(o=o.substring(n.length)),n+="\n"+o.trim(),n&&c.stackTraceRegExp&&c.stackTraceRegExp.test(n)){var t=e.filename||r&&(r.fileName||r.sourceURL)||"",a=e.lineno||r&&.....
     
    Last edited: Jan 18, 2022
    KoosyCrypto likes this.
  10. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    @jayray2000
    No need to mess with Unity's files, there already is a real solution in post #4.
     
  11. jayray2000

    jayray2000

    Joined:
    Jan 19, 2014
    Posts:
    2

    That's right, but I have no idea where to find the web.xml file or where to put it on my server.... ;-)
     
  12. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    It should already be on the server. If you don't know what you're doing, then the last thing you should do is messing with Unity's files and disabling the error won't fix the underlying problem anyway.
     
  13. Vixxd

    Vixxd

    Joined:
    Jul 25, 2016
    Posts:
    11
    Could you tell us where the 'web.xml' file is expected to be found on an Apache server? I am using shared hosting and familiar with updating .htaccess and .httpconf files but not web.xml files. I have been uploading WebGL builds to this particular server for years and never encountered this before doing a WebGL build with Unity 2021. I have contacted my webhost support chat and requested they update the 'web.xml' file and they said it does not exist.

    EDIT: I added the following to the .htaccess file within the root of my project (where index.html is) and that resolved the issue - did not need to locate the web.xml.

    Code (csharp):
    1. AddType application/wasm wasm
     
    Last edited: Jan 20, 2022
  14. Vixxd

    Vixxd

    Joined:
    Jul 25, 2016
    Posts:
    11
    I added the following to an .htaccess file (I created myself) within the root of my project (where index.html is) and that resolved the issue - did not need to locate the web.xml.

    Code (csharp):
    1. AddType application/wasm wasm
     
  15. Vickrpg

    Vickrpg

    Joined:
    Dec 3, 2016
    Posts:
    1
    do you just create a blank .httaccess text file with that as the only line? I also have no web.xml file.
     
  16. Vixxd

    Vixxd

    Joined:
    Jul 25, 2016
    Posts:
    11
    I did already have one for subdirectory settings but creating a new blank one should have the same result.
     
  17. josefnpat

    josefnpat

    Joined:
    Apr 17, 2013
    Posts:
    10
    For anyone using Apache2, you can either use .htaccess as mentioned in post #14, but some apache installations don't have .htaccess files enabled, like mine.

    I added `AddType application/wasm .wasm` to `/etc/apache2/ mods-enabled/mime.conf`

    This worked for Apache/2.2.22 (Ubuntu)
     
    livium and Vixxd like this.
  18. floatingfehrsen

    floatingfehrsen

    Joined:
    May 15, 2020
    Posts:
    2
    For me .htaccess did work and couldn't find web.xml but adding a file named web.config to the directory with index.html worked, the content is;


    <configuration>
    <system.webServer>
    <staticContent>

    <mimeMap fileExtension=".wasm" mimeType ="application/wasm" />
    </staticContent>
    </system.webServer>
    </configuration>
     
  19. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
  20. trasmouss

    trasmouss

    Joined:
    Jul 28, 2021
    Posts:
    1
    not work, not work, not work :(
     
  21. Cusmat

    Cusmat

    Joined:
    Sep 17, 2021
    Posts:
    2
    Thank you
     
  22. sparkyu

    sparkyu

    Joined:
    Apr 16, 2022
    Posts:
    1
    This works for my wordpress
     
  23. xTheTimeSte

    xTheTimeSte

    Joined:
    Apr 4, 2021
    Posts:
    5
    this fixed + + +
     
  24. KoosyCrypto

    KoosyCrypto

    Joined:
    Jul 21, 2022
    Posts:
    3
    Can you make video how to fix that please?
     
  25. KoosyCrypto

    KoosyCrypto

    Joined:
    Jul 21, 2022
    Posts:
    3
    Thanks you, your solutions work for me
     
  26. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    258
    For anyone else encountering this problem, the suggestion in comment #9 merely removes the error message and does not address the cause of the error!

    The solution to this problem is to configure your web server with the proper MIME type association, which is specific to your web server and documented for some common choices here:
    https://docs.unity3d.com/Manual/webgl-server-configuration-code-samples.html
     
    ENRI2, LilGames, Waranoi and 2 others like this.
  27. FaridCG

    FaridCG

    Joined:
    Nov 17, 2016
    Posts:
    4
    Unfortunately, none of the answers helped me. I just deleted in index.html this one:
    warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
     
  28. dreg_master

    dreg_master

    Joined:
    Jan 4, 2016
    Posts:
    44
    create a .htaccess file and place it in the directories before the project

    <IfModule mod_mime.c>
    AddEncoding gzip .unityweb
    </IfModule>
    AddType application/wasm wasm
     

    Attached Files:

    • 1.png
      1.png
      File size:
      6.8 KB
      Views:
      713
    • 2.png
      2.png
      File size:
      9.3 KB
      Views:
      656
  29. jcameron47

    jcameron47

    Joined:
    Dec 15, 2015
    Posts:
    7
    Thank you, that did the trick. Don't see a web.xml, added blank .htaccess with this fix, works. I had to clear my history with the site for the warning to be gone next time.
     
  30. AfricanStudios

    AfricanStudios

    Joined:
    Apr 14, 2020
    Posts:
    2
    for my on Apache 2.4.6 I added to my etc/mime.types . Tried all the other methods, they didn't work for me.

    Code (CSharp):
    1. application/wasm    wasm
     
  31. pkcooper

    pkcooper

    Joined:
    Dec 12, 2022
    Posts:
    2
    Another idea that worked for me... Change the 5000ms timer to 5, and change the background padding color to black. It just looks like a normal load function in my game.

    function unityShowBanner(msg, type) {
    function updateBannerVisibility() {
    warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
    }
    var div = document.createElement('div');
    div.innerHTML = msg;
    warningBanner.appendChild(div);
    if (type == 'error') div.style = 'background: black; padding: 10px;';
    else {
    if (type == 'warning') div.style = 'background: black; padding: 10px;';
    setTimeout(function() {
    warningBanner.removeChild(div);
    updateBannerVisibility();
    }, 5000);
    }
    updateBannerVisibility();
     
  32. halinc

    halinc

    Joined:
    Feb 24, 2019
    Posts:
    32
    suddenly got the same error after a new build and couldn’t explain why as it was working fine before (without any .htaccess file).

    silly mistake really: make sure you don’t use a development build :)
     
  33. ChuChuRocket

    ChuChuRocket

    Joined:
    Dec 9, 2022
    Posts:
    1
    In Apache 2.4 on Windows 10 Home, you can add the following line to "httpd.conf" file inside the "<IfModule mime_module>" section.

    AddType application/wasm .wasm
     
    jacksonkr likes this.
  34. ExNinja

    ExNinja

    Joined:
    Dec 4, 2013
    Posts:
    30
    [Unity 2020.3.38]
    Another option is to enable both some sort of Decompression (GZip or Brotli) and Decompression Fallback in your WebGL settings. This causes all of the files in your WebGL Build folder other than _.loader.js to have the extension .unityweb appended, avoiding the .wasm configuration issue. (For example, myGame.wasm would now be myGame.wasm.unityweb .)

    This, of course, may also be slow, but it does bypass the error without having to go into any web server settings.
     
    LilGames likes this.
  35. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    976
    Resolved by editing htaccess, but why is the app loading so long?
    About 20–40 seconds with Wi-Fi after the loading bar crosses the almost end
    For app with test line of code...
     
    Last edited: Jun 11, 2023
  36. OrbitalDuck

    OrbitalDuck

    Joined:
    Oct 26, 2013
    Posts:
    54
    I had a similar issue and just couldnt get it to work so asked my hosting company (clook.net) to see if they could help and they did.

    They added:

    headerfix.png

    they used the Header Set directive at the bottom of the htaccess file in /Build/ to force the correct header on the files.
     
    jukka_j likes this.
  37. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    That's nice to see that web hosts were able to accommodate. If they can also add .wasm.br to that list, that would enable them to run Brotli-compressed content as well.
     
    OrbitalDuck likes this.