- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
MDN 建议您执行以下操作来创建和填充服务工作线程缓存:
this.addEventListener('install', function(event) {
event.waitUntil(
caches.open('v1').then(function(cache) {
return cache.addAll([
'/sw-test/',
'/sw-test/index.html',
... etc ...
]);
})
);
});
我不明白该代码。 waitUntil
方法也有文档记录,上面的代码似乎是它目前存在的唯一目的:
The ExtendableEvent.waitUntil() method extends the lifetime of the event. When called in an EventHandler associated to the install event, it delays treating the installing worker as installed until the passed Promise resolves successfully. This is primarily used to ensure that a service worker is not considered installed until all of the core caches it depends on are populated.
我不明白的是:
waitUntil
通常如何影响代码流?它会阻止事件传播直到它的 promise 得到解决吗?我问这个问题是因为我对上面的代码有疑问,我想理解它。
最佳答案
正如描述所说:
the
ExtendableEvent.waitUntil()
method extends the lifetime of the event.
如果您不在方法内调用它,则服务工作线程可能随时停止(请参阅 the specification )。
因此,waitUntil
方法用于告诉浏览器不要终止 Service Worker,直到传递给 waitUntil
的 Promise 得到解决或拒绝。
关于您的具体问题:
install
和 activate
事件,它会延迟 Service Worker 到 installed
和 的状态切换已激活
(请参阅 specification of the waitUntil method ,特别是该段落的最后一部分)。关于javascript - event.waitUntil 在 Service Worker 中做什么以及为什么需要它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37902441/
a: 1---2-3-4--5---6 b: ------T--------- o: ------1234-5---6 使用RxJS,有没有什么算子可以完成上图?我有一个流 A,它是一个随机的事件流,
我们使用 Jenkins 管道进行构建和测试。构建完成后,我们在多个测量设备上运行自动化测试。 为了更好地了解所需的测试时间,我创建了一个测试阶段,它会定期检查测试的状态。当所有测试完成后,管道就完成
我有一个管道阶段,我等待从 sh 脚本返回某个字符串,并且只有当字符串匹配时,才继续到下一个阶段,但是,它无法按预期工作: node('master') { stage("wait for b
我正在使用 wedriverio 4.5: ./node_modules/.bin/wdio -v v4.5.2 我需要等到某个元素存在,如果不存在则处理这种情况。 例如: let element =
因此,如果我使用 await page.waitFor(9000) 或一些硬编码的等待号码,我的函数将等到页面加载。 但是,await page.goto(url, {'waitUntil': 'ne
在学习 JavaScript 时,它建议使用 async/await,因为它比 .then 更具可读性,我同意。不幸的是,当谈到 PWA 服务 worker 时,async 似乎被遗忘了。 尝试为具有
我需要 chrome 注册 ID 将其作为参数发送给 API 调用,这样我就可以获取与注册 ID 对应的消息。我的代码如下: self.addEventListener('push', functio
是否有必要在 respondWith(本身在 fetch 事件中)中使用 waitUntil? respondWith 是否已经waitUntil 收到已解决的 promise ? 对此的一些讨论是
我已经正确安装了 ServiceWorker,我正在使用以下代码监听同步事件: self.addEventListener("sync", function(event) { console.lo
正如您在文档中看到的,waitUntil 方法受到 ElementsCollection 的保护: http://selenide.org/javadoc/3.7/com/codeborne/sele
在 WebdriverIO 中,我想等到浏览器重定向到其中包含单词 project 的 URL。我尝试组合 waitUntil 和 getUrl 函数,但它给出了错误消息。 类型错误:browser.
是否可以让 Service Worker 等待开始处理 fetch 事件,直到 Service Worker 启动时异步工作完成? 我有一个应用程序外壳,其路由在数据中定义。要在 service wo
MDN 建议您执行以下操作来创建和填充服务工作线程缓存: this.addEventListener('install', function(event) { event.waitUntil(
我有一个验证类,它使用线程池来处理它的所有作业。 现在,当用户询问时,我会启动一个线程,通过从磁盘读取作业来为我的验证类提供作业。而且我确信在某一时刻阅读会比处理更快。因此,我想编写一个方法,允许该线
也许我正在翻译domcontentloaded错误,但我希望当时所有元素都可以访问,并且查询它们应该不会有问题。 考虑以下因素: await page.goto(url, { waitUntil: '
在使用 async/await 语法时,我正在为 service worker 中的 promises 而苦苦挣扎。 以下情况:我收到推送通知,想处理点击事件。如果我将“旧”语法与 then 和 ca
我正在使用 puppeteer 来评估我的测试应用程序中基于 javascript 的网页 HTML。 这是我用来确保所有数据都已加载的行: await page.setRequestIntercep
在非常高的级别上,我们单击一个命令建筑物控制点的按钮;打开或关闭灯。单击应该向服务器发送 POST 请求。问题是有时单击按钮但 POST 请求不会发出。该按钮没有指示它是否已被单击的功能(小幅增强)。
我是一名优秀的程序员,十分优秀!