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?
Answer by RobereStarkk · Aug 30, 2016 at 08:09 AM
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.
I have fixed this issue by opening my /etc/httpd/conf/httpd.conf apache configuration file, and going to the mime_module section. I replaced
AddType application/x-gzip .gz .tgz
with
AddType application/x-gzip .gz .tgz .memgz .jsgz .datagz
and now my browser is automatically decompressing the files when it gets them.
thanks - this worked for me. Had to sudo vi the httpd.conf to have write permissions.
Thanks. I've created an .htaccess file in my user directory, containing only the line you give below, and... no dice. "Illegal character" when I try to run the program through my browser, even though the build works fine when running locally.
Answer by KEMBL · Oct 04, 2016 at 08:47 PM
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.
Thanks, but as I said, I don't ad$$anonymous$$ister this server so I haven't got authority to reset it. Based on other advice I've created a ".htaccess" file in my own user directory, containing only this text:
AddType application/x-gzip .gz .tgz .memgz .jsgz .datagz
I haven't got a "directory config" section or indeed any sections at all in this file. What specific text can I add to the file to apply your advice, assu$$anonymous$$g I can do that without resetting the whole server?
By the way, is it normal for a WebGL build to take nearly half an hour and mostly make the whole PC hang, when a Webplayer build in Unity 4 took maybe 2 $$anonymous$$utes?
Hello, you cannot use the Directory directive in .htaccess file, but it is not needed cause everything that you put to it related to directory where it is placed.
Lets see more deep into situation.
That AddType directive does not work because it says - "for every requested file with extention .datagz, etc. add content type application/x-gzip" BUT web browser does not make http request to .datagz like
http://yourpage.com/projectpage/Release/webgl.datagz
It actually asks for
http://yourpage.com/projectpage/Release/webgl.data
and you do not have any directives for .data and you even have no such file in Release folder.
So, ----------- Solution 1-----------
If you have no any access to apache config files and limited in rights to set necessary .htaccess options: the obvious solution is to decompress
webgl.datagz, webgl.jsgz, webgl.memgz, *.unity3dgz
into
webgl.data, webgl.js, webgl.mem, *.unity3d
and upload them to Release folder. After this webgl.js becomes 25 meqabytes but apache in default setup still should compress it on-fly as it has text mime type. Yes, it will require more CPU utilization than just read compressed file from the file system but it should work.
----------- Solution 2 -----------
It could not work without rights but try to remove everything from your .htaccess file in project folder and add these strings to it.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENA$$anonymous$$E}gz -f
RewriteRule ^(.*)\.js$ $1\.jsgz [L]
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENA$$anonymous$$E}gz -f
RewriteRule ^(.*)\.data$ $1\.datagz [L]
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENA$$anonymous$$E}gz -f
RewriteRule ^(.*)\.mem$ $1\.memgz [L]
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENA$$anonymous$$E}gz -f
RewriteRule ^(.*)\.unity3d$ $1\.unity3dgz [L]
AddEncoding gzip .jsgz
AddEncoding gzip .datagz
AddEncoding gzip .memgz
AddEncoding gzip .unity3dgz
It is the same file these you can find in Release folder, so if it exists in Release folder you do not need to add anymore .htaccess cause obviously you have no rights.
----- Solution3 -----
As was suggested above edit js in index.html file these way that it will ask for http://yourpage.com/projectpage/Release/webgl.datagz and hope the browser will decode gz on-fly
i.e. change
dataUrl: "Release/webgl.data",
codeUrl: "Release/webgl.js",
memUrl: "Release/webgl.mem",
to
dataUrl: "Release/webgl.datagz",
codeUrl: "Release/webgl.jsgz",
memUrl: "Release/webgl.memgz",
if 3 does not work try to add .htaccess with only these strings
AddEncoding gzip .jsgz
AddEncoding gzip .datagz
AddEncoding gzip .memgz
AddEncoding gzip .unity3dgz
Hi All, Below given is the error that pops out in mozilla browser when I upload my webgl build to Apache server and trigger index.html file. [QUOTE]"An error occured running the Unity content on this page. See your browser's JavaScript console for more info. The error was: Uncaught unknown compression method."[/QUOTE] Unity version 5.5.X Compression format: Gzip. How should I solve this issue. All threads and forums are saying to modify .htaccess file but unity is not generating .htaccess file!! Help is appreciated. Thanks in advance
Your answer

Follow this Question
Related Questions
Web Build Text Assets Aren't Working 1 Answer
Unity 5.3 is Slower on WebGL and iPad 2 Answers
Drawing, Writing on screen. 0 Answers
WebGL and Python Building Errors 0 Answers
Is possible to Embed WebGL Compiled Game in Blogger? if Possible How? 2 Answers