使用Workbox预先缓存资产时跟踪进度 [英] Keep track of progress while precaching assets with the Workbox

查看:57
本文介绍了使用Workbox预先缓存资产时跟踪进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,一旦用户导航到网站,我们就需要N个资产与服务工作者一起进行预缓存.我们有适当的 precache-manifest.js 与列出的N文件,并且我们正在使用

Imagine we have N assets that need to be pre-cached with a service-worker once user navigated to the web site. We have appropriate precache-manifest.js with listed N-files and we are using workbox.precaching.precacheAndRoute([...]) to configure needed behavior (default CRA setup)

使用 workbox.precaching.precacheAndRoute workbox.precaching.precache ?

我想这可能就像将参数回调函数传递给 workbox.precaching.precacheAndRoute 以及要预缓存的条目数组一样.然后为每个缓存的条目调用此回调..

I imagine it could be something like passing a parameter-callback function to the workbox.precaching.precacheAndRoute along with the array of entries to precache. And this callback is invoked for each cached entry..

有没有解决此问题的方法或解决方法?谢谢!

Is there any solution or workaround for this issue? Thanks!

推荐答案

从理论上讲,应该可以添加您自己的

In theory it should be possible to add your own custom plugin to the precaching component using addPlugins

我希望能在不久的将来使用cacheDidUpdate事件来证明这一理论,但我不确定我是否可以轻松地将进度传达给页面.我心中的疑问是,我是否可以可靠地收听正在注册的页面中但尚未由预缓存服务工作人员控制的任何消息

I hope to have a play with proving this theory at some point soon using cacheDidUpdate event, I am not certain that I can communicate the progress easily back to the page though. The doubt in my mind is whether I can reliably listen to any messages in the page that is registering, but not yet controlled by the precaching serviceworker

这篇关于使用Workbox预先缓存资产时跟踪进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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