unity WebGL部署时的常见报错处理
Unable to parse Build/xxx.framework.js.br! 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: br" present. Check browser Console and Devtools Network tab to debug.
当出现这个错误时常见的解决方案是勾选打包设置的解压缩回退选项一般可以解决如图所示:
这个选项默认是不勾选的,如果想使用默认设置不勾选来使用压缩来提高性能最好使用第二种解决方案,这种方式官方文档有解决方案但是比较麻烦。参考:Server configuration code samples - Unity 手册
我这里使用的win11自带的iis服务器配置的,每个版本的iis服务器配置方式可能不一样,但都大同小异。先要安装url重写模块:URL Rewrite : The Official Microsoft IIS Site打开这个网站后下载对应的平台的安装包就能安装。安装后打开iis可以看到有URL重写选项。
打开webbgl发布目录下面的web.config配置文件在节点下面添加以下代码
此时就能完成了url重写的配置,再添加对应的MIME设置就不再报错能正常运行了。以下为web.config文件最终参考写法: