Search code examples
reactjsservice-workercreate-react-app

How can i exclude some urls from service worker with create-react-app?


I have app using create-react-app and service-worker generated on-a-build.

I checked out a lot of issues and articles, but still not found usable answer.

What is a best practice to add something like urlBlockList to create-react-app service worker?


I think react eject is not the most appropriate solution


Solution

  • Resolved

    Best solution that I found - use https://github.com/liuderchi/sw-precache-cra and add unwanted urls to custom sw-config

    Example:

    // sw-config.js
    module.exports = {
      runtimeCaching: [
        {
          urlPattern: '/unwantedurl',
          handler: 'networkFirst',
        },
      ],
    };