0

I am trying to convert a React web app to PWA (Progressive Web App). I have made the change in index.js file - serviceWorker.register();.

This is working fine as I am able to see the home page and assets in offline mode. But I want to cache API calls as well, which are cross origin.

I read create-react-app docs which say

By default, the generated service worker file will not intercept or cache any cross-origin traffic, like HTTP API requests, images, or embeds loaded from a different domain.

I couldn't find ways to change this default behaviour and intercept/cache cross-origin API calls in the docs.

I stumbled on this question from 2017 regarding the similar problem and solution seems to involve eject.

Now that some time passed since the above question, Is there any new way to intercept or cache any cross-origin traffic using create-react-app service worker without ejecting?

Smile
  • 3,832
  • 3
  • 25
  • 39

1 Answers1

1

I never done this before, but you can try to comment this condition in serviceWorker.js file:

enter image description here

Wiyanto Tan
  • 82
  • 1
  • 3