【发布时间】:2019-08-13 15:33:11
【问题描述】:
我正在尝试使用importScripts
self.addEventListener('fetch', event => {
...
self.importScripts('idb.js');
...
}
为 PWA 的 Service Worker 加载库,但不断获取
DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope':
The script at 'http://localhost:3000/idb.js' failed to load.
脚本文件在那里,内容类型正确,application/javascript,我也试过text/javascript。我的开发人员工具网络选项卡显示请求开始然后很快失败,没有机会访问服务器。通过 http 时状态码为 (failed) net::ERR_CONNECTION_REFUSED,通过 https 时为 (failed) net::ERR_FAILED。任何帮助表示赞赏
【问题讨论】:
标签: javascript service-worker progressive-web-apps web-worker