Local WebGL builds failing under Chrome

When I build for WebGL in Unity, I get this.

When I go to my cloud builds, and run the web build, it works fine.

When I download the cloud build and put the folder on my web server, I get the same error.

When I check the console, the indicated location of the error is the error handler in UnityLoader.js which is not especially helpful. So the only information I have on this is “there is a < somewhere it doesn’t belong” and holy crap that is not enough to try and fix anything web-based ever.

I cannot imagine that I am the only person with this problem, so surely someone has found and fixed it, right? Maybe an updated UnityLoader.js or something?

Workaround found: turn off compression in Player Settings → Publisher Settings.

That’s disappointing, because any problem you can avoid by clicking a couple buttons tends never to be fixed. The problem hasn’t gone away, I’m just going around it.

does it run correctly if you build locally?

This was not a known issue. The best way to make sure a bug does not get forgotten is to submit a bug report.

I’m not sure what you’re asking.

If I build for Windows 32- or 64-bit locally, it runs fine. If I build for Web GL locally, I get this error when I put it on my web server and load the generated index.html file.

If I cloud build for Windows 32- or 64-bit, it runs fine. If I cloud build for Web GL, it runs fine from the cloud build page, but gives the same error when I download that build and put it on my web server.

It looks like there’s something wrong with my web server configuration, but I can’t tell what. If I build locally with compression off, the resulting build works fine on my server, so it seems reasonable that there’s something going on with gzip handling on my server. I just can’t figure out what it is.

I don’t know what the bug is. Maybe it’s compression. Maybe it’s SSL. Maybe it’s web.config (LOL, not on Apache it’s not). All of those are potential solutions according to this thread, which came up when I searched for “unexpected token unity compression” trying to find an explanation of why it has to be turned off.

https://forum.unity3d.com/threads/uncaught-syntaxerror-unexpected-token.322684/

If I made a bug report, it would be no better than that thread, which is more than a year old so how is this not a known issue? (Answer: because nobody else made a bug report either, obviously.)

I’m trying to lock down what it is, because I’d like to have compression turned on for efficiency purposes. I’m just not getting much of anywhere.

I see. Yes, It seems like it’s a server configuration problem so nothing we can do on our side. Does this help ?

Possibly. It does give me some pointers to what might be needed; I’ll muck around in .htaccess and see what I can come up with.

EDIT: Ughhhhhhh. I dug into my supply of “domains I have not mapped to any server” and added a brand new domain to my server so I could get a clean test. The compressed build works just fine there. But I move the folder to my primary domain, and I get the error again. They’re just different folders on the same server, so wtf.

Went back to my main web server and hooked up the proper bits from the documentation, as @Marco-Trivellato suggested:

Put these blocks into .htaccess and everything is now working fine. Not sure what might have helped prevent me from hitting this error, though… if I come up with any ideas, I’ll suggest them.

Also take care on how you cache your file on your web server (if you cache it) because i had an issue with few players who have got the same error when i cached the file and updated my game to a new version. So i have removed the cache (file date) and since, i have never go any report .