Search code examples
create-react-appworkbox

Configure CRA-generated app to NOT download Workbox from CDN, but a local copy


I am looking for a recommendation on configuring my CRA-generated app's generated Workbox service-worker.js to fetch the Workbox library from my main app bundle's workbox library, so that the app does not need to depend on Google's CDN. By default, the CRA app loads workbox from the Google CDN.

Specifically, I want the generated line importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js"); inside the generated serice-worker.js file to be replaced.

There seem to be no elegant solutions to configuring this, and I would be super appreciative if someone could guide me forward. Thanks!


Solution

  • I would recommend using create-react-app v4, along with the cra-template-pwa.

    That will give you a Workbox-based service worker that is self-contained and does not depend on loading anything from the CDN.

    Earlier versions of c-r-a unfortunately are not customizable in this regard.