Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immediately install new service worker on refresh #1791

Closed
taoeffect opened this issue Dec 11, 2023 · 1 comment
Closed

Immediately install new service worker on refresh #1791

taoeffect opened this issue Dec 11, 2023 · 1 comment
Assignees
Labels
App:Frontend Kind:Enhancement Improvements, new features, performance upgrades, etc. Priority:High

Comments

@taoeffect
Copy link
Member

Problem

Have a look at this comment.

It turns out that the way that service workers update is a bit convoluted and non-optimal by default.

The article says:

After it's successfully installed, the updated service worker delays activating until the existing service worker is no longer controlling clients. This state is called "waiting", and it's how the browser ensures that only one version of your service worker is running at a time.

However, that last sentence is somewhat non-sensical / wrong, because it's contradicted later down the page here:

The waiting phase means you're only running one version of your site at once, but if you don't need that feature, you can make your new service worker activate sooner by calling self.skipWaiting().

This causes your service worker to kick out the current active worker and activate itself as soon as it enters the waiting phase (or immediately if it's already in the waiting phase). It doesn't cause your worker to skip installing, just waiting.

Since calling self.skipWaiting() kicks out the old service worker, there is still only "one version" of the service worker running at a time. So it sounds like we can safely call self.skipWaiting() all the time.

Solution

Double-check what I'm saying above, and if it's right:

  1. Call self.skipWaiting()
  2. Do a manual call to update() on page refresh
  3. Call update() once per hour
  4. And we may also want to call clients.claim()
@taoeffect taoeffect added Kind:Enhancement Improvements, new features, performance upgrades, etc. App:Frontend Priority:High labels Dec 11, 2023
taoeffect pushed a commit that referenced this issue Jan 12, 2024
* add a sbp selector for manually updating the service-worker

* call Registration.update() immediately / set up 1hr periodic timer for it

* remove useless console.log

* check WebSocket.CLOSED / WebSocket.CLOSING before sending message to the push-server

* set up a event listener for PUBSUB_RECONNECTION_SUCCEEDED sbp event

* fix the typo

* minor updates
@taoeffect
Copy link
Member Author

Closed in #1799

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App:Frontend Kind:Enhancement Improvements, new features, performance upgrades, etc. Priority:High
Projects
None yet
Development

No branches or pull requests

2 participants