Search code examples
service-workeramazon-cloudfront

Service Worker caching wrong content


We have an angular application whose front end is hosted in S3 and backend is hosted in EC2. Our cloudfront has two origins. Any request with /api are going to our backend EC2 origin and without /api are going to S3. Now, we are seeing some of the requests without /api are going to s3 and serving index.html. We reached out to AWS support and they proved it that if we have service worker installed in our browser, then browser is internally sending request for index.html to the cloud front. This behaviour is intermittent and can be fixed by deregistering service worker. But that is not an option to go to all users and tell them to deregister service worker. Wanted opinion on what could have caused the issue and how this could have been solved.We do not want to get rid of service worker in our progressive web app.


Solution

  • This is fixed by changing the default configuration of ngsw-config.json. We had to add our APIs with "/api" under "datagroups". That solved the issue