Reputation: 5736
I have a unity webgl project and I pushed the webgl build to my git branch as shown below.
I deployed this branch to my github page as shown below.
The build is working on my local with the help of servez. However, on github pages (and my local without servez) it gives the following error:
Unable to parse Build/vectorunknown builds.framework.js.gz! 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: gzip" present. Check browser Console and Devtools Network tab to debug.
How do I deploy to github page with "Content-Encoding: gzip" response header included? How do I make it work? Do I need to make webgl with different options in Unity instead? Kindly help!
Upvotes: 6
Views: 11385
Reputation: 610
Here's why the marked solution is a tradeoff, not a solution. Making something work isn't necessarily solving the problem.
If you disable compression in WebGL, your build will have a significantly larger size, causing prolonged load time and a larger download size. So, by 'hacking' it, you introduce two new problems to make some error messages you don't understand disappear.
saved 40 MB using compression
On the following page, you can find the necessary configuration to allow content decoding from your server (depending on what you use):
https://docs.unity3d.com/Manual/webgl-server-configuration-code-samples.html
For example, I use Apache, and by simply adding a .htaccess
to my build's root with the following content, I was able to use, in my case, gzip
compression, and it loaded very quickly compared to uncompressed format (wasm
).
<IfModule mod_mime.c>
RemoveType .gz
AddEncoding gzip .gz
AddType application/gzip .data.gz
AddType application/wasm .wasm.gz
AddType application/javascript .js.gz
AddType application/octet-stream .symbols.json.gz
AddType application/wasm .wasm # need this line to serve decompressed wasm file
</IfModule>
That finishes the decompression server configuration and allows your server to load the gzip content.
Note that this might also be a workaround, since Unity doesn't account for gh-pages server.
Namely, the thing you could try with GitHub pages would be to use the .gitattributes
file at the root of your repository, with the following configuration
*.data.gz binary
*.wasm.gz binary
*.js.gz binary
*.symbols.json.gz binary
*.wasm binary
disclaimer: not sure if it will work
Upvotes: 2
Reputation: 27994
I had the same error message. When I inspected network traffic using browser developer tools, I could see no "Content-Encoding: gzip" response header. I added the mime types required by Unity to the server configuration, but still couldn't get the needed Content-Encoding response header to appear.
However, I found that enabling Player Settings > Publishing Settings > Decompression fallback solved the problem for me. According to these docs, "The decompression fallback option enables Unity to automatically embed a JavaScript decompressor into your build. This decompressor corresponds to your selected compression method, and decompresses your content if the browser fails to do so."
Presumably there's a somewhat slower startup because of having to download the JavaScript decompressor.
Upvotes: 5
Reputation: 5736
I went to Edit > Project Settings > Player > Publishing settings
and disabled the compression. it worked after that. However, the colors look weird after that. i wish there was another better way.
Upvotes: 3