Service Worker中的importScripts [英] importScripts in service worker

查看:268
本文介绍了Service Worker中的importScripts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用importScripts的阿基博尔德基于承诺的IDB库使用IndexedDB,但是通过Chrome Dev Tools选择离线"后,我会得到An unknown error occurred when fetching the script.有趣的是,即使关闭了我的本地主机服务器,我的应用程序也可以在安装了Service Worker的浏览器上正常运行(通过Chrome Dev Tools禁用了浏览器缓存),但在另一个浏览器上却无法运行.

我已经研究了这些 https://www.w3.org/TR/service-workers/#importscripts https://github.com/w3c /ServiceWorker/issues/106 资源,但我没有找到解决问题的方法.

任何帮助/解释将不胜感激.

解决方案

问题可能是您尚未缓存idb.js文件,以便服务工作者可以在您的应用程序脱机时访问它.

尝试在install回调中使用cache.add(如果要缓存多个文件,则使用cache.addAll)添加它.

I am trying to use IndexedDB through Jakes Archibald's promise-based IDB lib by importScripts but as soon as I select "offline" through Chrome Dev Tools I am getting An unknown error occurred when fetching the script. A funny thing that's happening is that even if shut down my localhost server my app works fine (I have the browser cache disabled through Chrome Dev Tools) on my service worker installed browser but on another, of course, it doesn't.

I've looked into these https://www.w3.org/TR/service-workers/#importscripts, https://github.com/w3c/ServiceWorker/issues/106 resources but I didn't find an fix to my problem.

Any help/explanation would be greatly appreciated.

解决方案

The problem is likely to be that you've not cached the idb.js file so that the service worker can access it when your app is offline.

Try adding it using cache.add (or cache.addAll if you are caching multiple files) inside your install callback.

这篇关于Service Worker中的importScripts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆