Marek Sekyra
Marek Sekyra

Reputation: 185

Angular service worker ignores relative path

I have an angular run that does run under a certatin path e.g. https://host:port/path/

When I load app and ngsw-cache-bust is run it ignores the path and tries to fetch script directly from the root path https://host:port/script.js instead of fetching it from https://host:port/path/script.js

I added pwa by running ng add @angular/pwa

I tried several ways of registering e.g. /ngsw-worker.js or ./ngsw-worker.js and none of these seems to fix it

We use Angular 7.2.0

ngsw-config.json looks like this

`

{
  "index": "/index.html",
  "routes": {
    "/": {
      "prefix": false
    },
    "/scripts": {
      "prefix": true
    },
    "/libraries": {
      "prefix": true
    }
  },
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
          "./favicon.ico",
          "./index.html",
          "./*.css",
          "/**.js"
        ]
      }
    }, {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**",
          "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
        ],
        "urls": [
          "https://fonts.googleapis.com/**"
        ]
      }
    }
  ]
}

`

Any help would be highly appretiated!

Upvotes: 5

Views: 1463

Answers (1)

Marek Sekyra
Marek Sekyra

Reputation: 185

I resolved id by adding a path inside prod script in package.json

    "prod": "gulp copy-assets && ng build --prod --progress=false --base-href=/abcd/",

Upvotes: 3

Related Questions