Angular Service Worker Communication

JS
S
JavaScript

In this snippet we show Angular's API for SW communication.

1// Check for Application Updates `ngsw.json`
2import { SwUpdate } from '@angular/service-worker';
3  ...
4  ngOnInit() {
5    if (this.swUpdate.isEnabled) {
6      this.swUpdate.available.subscribe(() => {
7          if (confirm('New version available. Load New Version?')) {
8              window.location.reload();
9          }
10      });
11    }
12  }

Created on 6/25/2018