KyelJmD
KyelJmD

Reputation: 4732

How to disable service worker for sub domains?

I have a webapp that is running with angular and it has a running service worker. Whenever I perform a PUT and GET operations on s3.amazonaws.com the request is always made from a service worker.

What configuration can use to make my request that is going to and from s3.amazonaws.com to be ignored by service worker?

Here is my nsgw-config.json

{
  "index": "/index.html",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
          "/favicon.ico",
          "/index.html",
          "/*.css",
          "/*.js"
        ]
      }
    }, {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**"
        ]
      }
    }
  ]
}

Upvotes: 0

Views: 978

Answers (1)

Pankaj Rupapara
Pankaj Rupapara

Reputation: 780

if you want to prevent duplicate service worker call then please do few steps as below.

  1. build your project production mode.
  2. goto build folder (default is /dist)
  3. open ngsw-worker.js file under /dist directory.
  4. find onFetch(event) { function
  5. modify the onfetch function like below

    onFetch(event) {
    

    /* sub domain URL here and subdomain ajax all domain here.*/

    var blackListDomain=["www.xyz.com/api","www.abc.com/v2/api"];
    
    for (var i = 0; i < blackListDomain.length; i++) {
        if (event.request.url.indexOf(blackListDomain[i])>-1) {
             console.log("revent " + event.request.url);
            return;
        }
    }
    

Hint

enter image description here

Upvotes: 1

Related Questions