question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service Worker: allow service worker to checkForUpdate and activateUpdate before bootstraping the AppModule

See original GitHub issue

🚀 feature request

Provide a way to check for updates and activate them before the main AppModule is bootstrapped.

Relevant Package

This feature request is for @angular/service-worker

Description

Currently, if we use the service worker module(which we want to use in order to support offline mode) we have no choice but always serve a cached(potentially outdated) version when a user opens our app. And only then we can check for updates in the background.

What we want is to check for updates before bootstrapping the app and if there are any then first activate them and only after that bootstrap an app. We want to be sure that a user starts her working day with a fresh version of our app (if for example there was an overnight update).

We considered force page reload and showing a prompt for a user to activate a new version but that would not be the best UX choice in our scenarios(we do updates a couple of times daily).

Describe the solution you’d like

Provide an API to access service worker’s checkForUpdate, available and activateUpdate properties outside of a module/service so it can be done in main.ts.

Describe alternatives you’ve considered

We can’t remove the service worker since we want offline support. We can’t force refresh as it’s a bad UX for us(we can on navigation between routes but that would be too late) We can’t show prompt as it will appear almost every morning for the user.

We consider showing a spinner in app.component until we make all checks through the ServiceWorkerModule as an alternative but that would be a waste of the device’s(in case of mobile) resources to parse and execute all JS to then find out it’s not needed.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gkalpakcommented, Oct 1, 2020

You are welcome. I’ll go ahead and close this issue, since it is not actionable as is (i.e. we will not expose SwUpdate outside of the Angular app - and even that wouldn’t be a great solution anyway).

I’ll let you play with the data-group work-around and eventually #38565 (in v11). Feel free to open a new issue to suggest further changes/enhancements to the SW configuration capabilities (e.g. specifying a timeout for navigation requests with the freshness strategy). (Also, feel free to continue the discussion below, if needed.)

0reactions
angular-automatic-lock-bot[bot]commented, Nov 1, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service worker communication - Angular
The service worker checks for updates during initialization and on each ... updates: SwUpdate) { // Allow the app to stabilize first, before...
Read more >
Service worker communication - Angular - w3resource
Importing ServiceWorkerModule into your AppModule doesn't just register ... Asking the service worker to check the server for new updates.
Read more >
Angular Service Worker SwUpdate.available not triggered
If I change the name of a button, build the app and put it onto my server the app still shows the old...
Read more >
Angular Service Worker - Step-By-Step Guide
Learn all about the multiple PWA caching configuration options of the ngws-config.json file, build Progressive Web Apps using the Angular ...
Read more >
The Complete Guide to Service Worker and PWA in Angular
isEnabled](https://angular.io/api/service-worker/SwUpdate#isEnabled)() . Getting started with service workers. This document explains how to enable Angular ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found