Skip to content

Commit daa09de

Browse files
devversionjelbourn
authored andcommittedAug 15, 2018
fix: remove service worker (#503)
* Removes the service worker for the material.angular.io docs page * Unregisters previously registered service workers and force-reloads the page if someone opens the docs and still has a service worker installed.
1 parent 7c9e931 commit daa09de

File tree

7 files changed

+41
-80
lines changed

7 files changed

+41
-80
lines changed
 

‎material.angular.io/angular.json

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"extractLicenses": true,
6969
"vendorChunk": false,
7070
"buildOptimizer": true,
71-
"serviceWorker": true,
7271
"fileReplacements": [
7372
{
7473
"src": "src/environments/environment.ts",

‎material.angular.io/ngsw-config.json

-49
This file was deleted.

‎material.angular.io/package-lock.json

+18-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎material.angular.io/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"@angular/platform-browser": "^6.0.9",
3232
"@angular/platform-browser-dynamic": "^6.0.9",
3333
"@angular/router": "^6.0.9",
34-
"@angular/service-worker": "^6.0.9",
3534
"core-js": "^2.5.6",
3635
"moment": "^2.22.1",
3736
"rxjs": "^6.1.0",

‎material.angular.io/src/app/app-module.ts

-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import {
3232
CanActivateComponentSidenav
3333
} from './pages/component-sidenav/component-sidenav-can-load-guard';
3434
import {HttpClientModule} from '@angular/common/http';
35-
import {ServiceWorkerModule} from '@angular/service-worker';
36-
import {environment} from '../environments/environment';
3735
import {GaService} from './shared/ga/ga';
3836

3937
@NgModule({
@@ -45,7 +43,6 @@ import {GaService} from './shared/ga/ga';
4543
HttpClientModule,
4644
MatNativeDateModule,
4745
RouterModule.forRoot(MATERIAL_DOCS_ROUTES),
48-
ServiceWorkerModule.register('/ngsw-worker.js', {enabled: environment.production}),
4946
ComponentCategoryListModule,
5047
ComponentHeaderModule,
5148
ComponentListModule,

‎material.angular.io/src/main.ts

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
44
import {enableProdMode} from '@angular/core';
55
import {environment} from './environments/environment';
66
import {AppModule} from './app/';
7+
import {unregisterServiceWorkers} from './unregister-service-workers';
8+
9+
// Unregister all installed service workers and force reload the page if there was
10+
// an old service worker from a previous version of the docs.
11+
unregisterServiceWorkers()
12+
.then(hadServiceWorker => hadServiceWorker && location.reload(true));
713

814
if (environment.production) {
915
enableProdMode();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Unregisters all currently registered service workers and returns a boolean that indicates
3+
* whether there were service workers registered or not.
4+
*/
5+
export async function unregisterServiceWorkers(): Promise<boolean> {
6+
if (!navigator.serviceWorker) {
7+
return false;
8+
}
9+
10+
const registrations = await navigator.serviceWorker.getRegistrations();
11+
12+
// Walk through every currently registered Service Worker and unregister it. There can be
13+
// service workers from previous versions of the Angular Material docs.
14+
registrations.forEach(registration => registration.unregister());
15+
16+
return registrations.length > 0
17+
}

0 commit comments

Comments
 (0)
Please sign in to comment.