如果 Service Worker 没有立即激活,PWA 是否对用户不友好? [英] Aren't PWAs user unfriendly if the service worker is not immediately active?

查看:87
本文介绍了如果 Service Worker 没有立即激活,PWA 是否对用户不友好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布了另一个问题作为这个问题的蛮力解决方案(Angular:在其他任何事情之前完全安装 Service Worker) 但我想我会单独制作一个来讨论按预期使用 Service Worker 的用例.

I posted another question as a brute-force solution to this one (Angular: fully install service worker before anything else) but I thought I'd make a separate one to discuss the use case for when a service worker is used as intended.

根据service worker生命周期(https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle),SW 已安装,但只有在您重新加载页面后才处于活动状态(您可以claim()页面,但这仅适用于安装 Service Worker 后发生的调用).原因是如果更新现有版本,旧版本和新版本不会混合状态和缓存.我可以同意这个决定.

According to the service worker life cycle (https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle), the SW is installed but it's only active once you then reload the page (you can claim() the page but that's only for calls that happen after the service worker is installed). The reasoning is that if and existing version is updated, the old one and the new one do not mix states and caches. I can agree with that decision.

我无法理解的是为什么它在最初安装后不会立即激活.相反,它需要重新加载页面,除非您在 SW 中明确定义预缓存规则.如果您使用通配符定义缓存规则,则无法预缓存这些规则,因此您需要重新加载.

What I have trouble understanding is why it is not immediately active once it is initially installed. Instead, it requires a page reload unless you explicitly define precaching rules in the SW. If you define caching rules with wildcards, it's not possible to precache those so you need the reload.

给定一个单页 PWA(如 Angular),用户会发现它周围的站点和浏览器,但在该会话期间永远不会重新加载该页面.如果他们以后想离线使用该站点,则需要至少再刷新或重新打开该选项卡一次.这对我来说似乎是一个很大的陷阱.

Given a single page PWA (like Angular), a user will discover the site and browser around on it but the page will never be reloaded during that session. If they then want to use the site offline later, they need to have refreshed or re-opened the tab at least one other time. That seems like a pretty big pitfall to me.

我在这里遗漏了什么吗?

Am I missing something here?

推荐答案

您对 Service Worker 生命周期的理解是正确的,但我认为您提到的陷阱并没有您想象的那么严重.

Your understanding of the service worker lifecycle is correct but I do not think the pitfall you mentioned is as severe as you think it is.

如果我对您的理解正确的话,如果用户在初始浏览页面期间(在 Service Worker 处于活动状态之前)断开连接并且缺少离线资产,用户体验只会受到负面影响.如果这确实是您想要考虑的场景,那么可以在浏览器端 javascript 中预先缓存该离线资产.或者,正如您所提到的,您可以 skipWaiting()claim() 使服务工作者处于活动状态,而无需用户刷新页面.

If I understand you correctly, the user experience will only be negatively affected if the user loses connectivity during the initial browsing of the page (before the service worker is active) and is missing an offline asset. If this is truly a scenario you want to account for then that offline asset can be pre-cached in the browser-side javascript. Alternatively, as you mentioned, you can skipWaiting() and claim() to make the service worker active without the user refreshing the page.

这篇关于如果 Service Worker 没有立即激活,PWA 是否对用户不友好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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