ZeeShaN AbbAs
ZeeShaN AbbAs

Reputation: 1365

Service Worker not working for external images only

I am facing a strange issue with service worker. I need to load the images from external server so I am using the following configuration of ngsw-config.json

"dataGroups": [{
    "name": "api-performance",
    "urls": [
      "/api",
      "imagesketches/image/"
    ],
    "cacheConfig": {
      "maxAge": "1d",
      "strategy": "performance"
    }
  }]

When I load an image for the first time it take some time to load and then if I refresh the page it will load the image from the service worker as it can be seen in following image.

figure1

However if I make my browser offline it will not load the image from service worker although it is loading the images from assets folder as it can be seen from the following image

figure2

Even the API data is being cached correctly.

I have event tried adding the image url in the assetGroups as well but it didn't work.

I working on Angular5 based PWA. I am not sure if the issue is related to service worker of browser or angular implementation of it.

Any help would be appreciated.

Upvotes: 1

Views: 2441

Answers (1)

Anand
Anand

Reputation: 10140

It looks like the issue is only for images that you are trying to access from external domain (which is not explicitly stated in question I believe, correct me if I’m wrong)

Each service worker will service for only one domain or sub-domain if you use one. That’s how service workers are intended to work regardless of framework you use.

You can try foreign fetch https://developers.google.com/web/updates/2016/09/foreign-fetch

Upvotes: 0

Related Questions