1×
Become a member
to unlock all features
Autoplay

    Cache Third Party Resources from a CDN in a React PWA

    reactReact
    16.6.3-16.8.6

    Our service worker caches our static assets - but only those assets that are included in our React App. This means that assets like Bootstrap, which we're including from a third-party CDN, won't be included in the cache, because they're not available at webpack compile time.

    We'll change the service worker to add caching for those assets by using workbox's registerRoute method, and a regular expression to match the entire URL of the asset. We'll pick the staleWhileRevalidate cache strategy, though cacheFirst, or networkFirst would also be valid choices.

    Finally, we'll change the name of the cache they are stored by supplying a cacheName parameter.