3

I have created a new angular project and added @angular/pwa, I can't figure out how to get the service worker to work when the website is in a directory. I tried adding the folder to every link in ngsw-config.json and adding a dot before the links (which worked to make the angular app to run in a folder by using <base href="./">).

Editing the staturl in manifest.webmanifest to "start_url": "/folder/" made the app installable in chrome but it is still not available offline (HTTP ERROR 504).

Versions: Angular CLI: 8.3.8 Node: 10.16.3 @angular/pwa: 0.803.8

1058u4
  • 172
  • 1
  • 10

1 Answers1

0

Here is a solution: https://github.com/angular/angular/issues/25055#issuecomment-408073162 I had to replace ngsw-worker.js

1058u4
  • 172
  • 1
  • 10
  • 1
    Did you get this working @1058u4 ? If so would you mind sharing the steps required? Eg. whatever values you had to set such as cope, start_url etc. I still can't get offline to work with /folder, even using the replacement ngsw-worker.js Thanks! – Shane Dec 12 '19 at 14:32
  • Hi, sorry for the late answer, I was inactive on this account. I am sure you already found a solution or moved on by now but for everyone with the same problem: I also added a registration strategy to the ServiceWorkerModule in the file src/app/app.module.ts: `ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production, registrationStrategy: 'registerImmediately' }),` I hope this helps! – 1058u4 Dec 04 '21 at 18:11