Cocos 3.8.x Access to script at 'chunks:///_virtual/Access to script at 'chunks:///_virtual/xxx.ts' from origin 'https://xxx.com' has been blocked by CORS policy: Cross origin requests are only...

错误码:

Access to script at 'chunks:///_virtual/xxx.ts' from origin 'https://xxx.com' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

原因:

Cocos 3.8.x打包成web-mobile或者web-desktop时,网速不佳时,被引用文件所在的bundle模块仍未加载时,必然报错。

调试bug必现方法:

在Chrome Network在Disable cache及Slow 3G模式下,必然会报这个错误。

解决方案:

给这些代码开一个优先级更高的Bundle。

或者暴力一点,也可以把代码直接扔到resources包里面去。

此方案启动开始场景(Start Scene)加载显示稍后些。

注意知识点:

https://www.cnblogs.com/wujinhong/p/18341406

bundle核心知识点:

https://www.cnblogs.com/wujinhong/p/18341405

总结:bundle设置最佳方案

posted @ 2024-07-25 21:30  风别鹤  阅读(79)  评论(0编辑  收藏  举报