WebGL Unusable: Unknown Compression Method, When Loading Text File

Hello. Windows 8, Unity 5.4.0f3 Personal, trying to build for WebGL. My old method in Unity 4 was to build for the WebPlayer, then just name the resulting .html and .build files something descriptive and upload them to my server, making sure the .html correctly references the .build name. Now with this WebGL build though, I’ve uploaded the .html file and the Release and TemplateData directories, opened the .html file in Firefox, and I get: “Unknown compression method.”

After forum-surfing, I tried renaming “Build.datagz”, “Build.jsgz” and “Build.memgz” within the Release directory, to remove the final “gz” of each. This time, the Web browser displayed a loading bar, and then the following:
“Syntax Error: Illegal character.”
(in Javascript console:)

Warning: NetUtil.asyncFetch() requires the channel to have one of the security flags set in the loadinfo (see nsILoadInfo). Please create channel using NetUtil.newChannel()
Invoking error handler due to
SyntaxError: illegal character
UnityLoader.js:1:31118
SyntaxError: illegal character:1

This build of my game consists of only a single scene, containing a script that’s supposed to load a text file from the Resources directory:

public Text thingy;

void Start()
{
    TextAsset t = (TextAsset) Resources.Load("test", typeof(TextAsset));
    Debug.Log(t);
    Debug.Log(t.text);
    thingy.text = t.text;
}

When running that in the editor, or building for WebGL and loading the resulting build on my own computer, it works, loading the text file “test.txt” and displaying its contents. What is going wrong between there, and having the exact same build work on a Web server?

If at all possible I’d like to avoid having to reconfigure the Web server just to support the new Unity, since I don’t own or administer that server. Incidentally, is it normal for the WebGL build process to take 15 minutes or so and lock up the mouse cursor, vs. 2 minutes to build for WebPlayer in Unity 4?

I am having this exact error when attempting to use the compressed version on my website.
Locally, my browser can handle the memgz etc files fine and uncompress them, as long as they aren’t in the format mem.gz, but when on my webserver the browser doesn’t handle them in either configuration.

It is possible to rename them to the .gz format, then gunzip them on the webserver and they will work, but quite slowly.

The local version does say in the browser console that the webserver can be configured to serve gz files somehow which will reduce the decompression time of the files, which is the biggest hint I’ve found that leaving it the way untiy outputs it and changing your webserver will make it work, but I’ve not found any information on how to do this.

Hello guys,

This solution is for apache webserver. It was checked with Unity 5.4.1p1 and httpd 2.2

After you have exported WebGL project and upload it to webserver you can find .htaccess file inside the Release subfolder. To have it works properly you should edit your apache config file and put this string:

AllowOverride FileInfo Options

inside the Directory config like this

    <Directory "/path/to/your/website/folder">

… some …
AllowOverride FileInfo Options
… some …

after this restart your webserver and everything should work well, in a case it does not take a look at your webserver errorlog file, probably something else should be corrected too.