我曾经将我的Unity WebGL构建托管在Apache服务器上,并使用.htaccess文件来启用WASM流传输并将.unityweb文件作为gzip服务,但现在我切换到Firebase Hosting,并希望重新启用此功能。
这是我的firebase.json文件:
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"headers": [
{
"source": "**/*.@(unityweb|wasm)",
"headers": [
{
"key": "Content-Encoding",
"value": "gzip"
}
]
},
{
"source": "**/*.@(wasm)",
"headers": [
{
"key": "Content-Type",
"value": "application/wasm"
}
]
},
{
"source": "application/wasm",
"headers": [
{
"key": "Add-Output-Filter-By-Type",
"value": "DEFLATE"
}
]
}
]
}
其功能应与此.htaccess文件相同:
AddEncoding gzip .unityweb
AddType application/wasm .wasm
AddEncoding gzip .wasm
AddOutputFilterByType DEFLATE application/wasm
我的构建功能没有统一启用wasm流,但是当我这样做时,连同此firebase.json设置一起,出现以下错误:
UnityLoader.js:4 wasm streaming compile failed: CompileError: WebAssembly.instantiateStreaming(): expected magic word 00 61 73 6d, found 1f 8b 08 18 @+0
UnityLoader.js:4 falling back to ArrayBuffer instantiation
UnityLoader.js:4 failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 1f 8b 08 18 @+0
CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 1f 8b 08 18 @+0
UnityLoader.js:4 CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 1f 8b 08 18 @+0
我以前没有在Apache上配置.htaccess文件时收到此错误。
由于我的Unity构建中出现以下消息,我试图将.unityweb文件托管为gzip:You can reduce your startup time if you configure your web server to host .unityweb files using gzip compression
。
有人知道如何让Firebase做到这一点吗?