Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serverless 版本发布后提示 ServiceWorker 无法注册 #229

Open
ai7hoo opened this issue Mar 25, 2020 · 1 comment
Open

Serverless 版本发布后提示 ServiceWorker 无法注册 #229

ai7hoo opened this issue Mar 25, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@ai7hoo
Copy link

ai7hoo commented Mar 25, 2020

打包发布到 Serverless 后,控制台报以下问题:

Service Worker SUPPORTED. ERROR DOMException: 
Failed to register a ServiceWorker: The origin of the provided scriptURL ('https://aaaa.com') does not match the current origin ('https://bbbb.com').
@Diablohu
Copy link
Member

问题原因

Service Worker 文件在他域名的 CDN 服务器上,跨域注册 Service Worker 不允许

解决方案

  • 新增配置 serviceWorker.publicPath,用以配置 Service Worker 文件访问前缀
    • 该配置默认为 /,即通过本域访问
  • Service Worker 文件也输出到服务器打包结果中
  • 服务器响应到 Service Worker 文件请求时,从服务器端结果中读取文件并返回
  • Workbox 尝试处理跨域请求的静态资源
    • 通过 ClientpublicPath 判断是否是打包的

@Diablohu Diablohu added the enhancement New feature or request label Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants