Angular 8 PWA application puts Server-Sent events in pending state forever

Viewed 348

It seems that only when application is compiled for production (PWA) in Angular 8 causes problems for the browser to receive SSE events from the server.

If I run the application in development mode (simply with ng serve) things work as expected. So my initial thought is that PWA is somehow the root of the problem.

I've tried to exclude the caching on the api /v1/events in ngsw-config.json but there is no difference:

{
    "name":"api",
    "urls": ["/api/v1/**"],
    "cacheConfig": {
      "maxSize": 0,
      "maxAge": "0u",
      "strategy": "freshness"
    }
  }

Anyone had a similar problem and managed to solve it properly?

1 Answers

I think i figured it out. I've simply added a call to my API /v1/events a query parameter to bypass the service worker: /v1/events?ngsw-bypass=true.

I found the answer on Angular web page

In some cases, you may want to bypass the service worker entirely and let the browser handle the request instead. An example is when you rely on a feature that is currently not supported in service workers (e.g. reporting progress on uploaded files). To bypass the service worker you can set ngsw-bypass as a request header, or as a query parameter. (The value of the header or query parameter is ignored and can be empty or omitted.)

Related