components icon indicating copy to clipboard operation
components copied to clipboard

Service worker on website

Open BePasquet opened this issue 8 years ago • 7 comments

Bug, feature request, or proposal:

I spotted that service worker doesnt claim and reloads website

What is the expected behavior?

i assume you know all this but maybe helps

if ("serviceWorker" in navigator) {
        navigator.serviceWorker.register('sw.js').then(x => console.log('SW registered'));
        navigator.serviceWorker.addEventListener('controllerchange', (ev) => {
            console.log('controller-change');
            window.location.reload();
        });
    }
self.addEventListener('install', () => {
    self.skipWaiting();
});

self.addEventListener('activate', (event) => {
    event.waitUntil(self.clients.claim());
});

What is the current behavior?

sometimes page just stay blank i have to skip awaiting on sw

What are the steps to reproduce?

Providing a StackBlitz reproduction is the best way to share your issue.
StackBlitz starter: https://goo.gl/wwnhMV

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Is there anything else we should know?

BePasquet avatar Jun 27 '18 06:06 BePasquet

just letting you know is not an issue for me

BePasquet avatar Jun 27 '18 06:06 BePasquet

You may get more attention filing an issue against the material.angular.io repo. Issue #472 is related.

jtwotimes avatar Jun 28 '18 16:06 jtwotimes

I also noticed this issue a lot of times in Chrome and Firefox. It happens when a new version of the website is deployed.

It is fixed if I clean the application cache storage directly from Devtools (Application > Clear storage > Clear site data) or by force refreshing the page (Ctrl + F5).

The issue is caused by ngsw-worker. Furthermore, I think it may be solved by enforcing mime type to the stored files.

razvantomegea avatar Jul 14 '18 10:07 razvantomegea

I'm not able to reproduce this locally but I tweaked some settings on the SW that might resolve this issue - https://github.com/angular/material.angular.io/pull/485

amcdnl avatar Jul 15 '18 17:07 amcdnl

image posible solution:


import { SwUpdate } from "@angular/service-worker";

@Injectable()
export class SWActivate {
  constructor(private swUpdate: SwUpdate) {
    this.swUpdate.available.subscribe(evt => location.reload());
  }
}
import { SWActivate } from "../core/services/sw-activate.service";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"]
})
export class AppComponent {
  constructor(
    private swActivate: SWActivate
  ) {
  }
}```

BePasquet avatar Aug 14 '18 09:08 BePasquet

Closing since we've removed the SW from the docs site temporarily

jelbourn avatar Oct 16 '18 22:10 jelbourn

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.