title: Workaround for cache size limit in Create React App PWA service worker
body: <p>I'm developing a PWA starting from a blank CRA template. The application needs to fully work offline after the installation, so I'm exploiting Workbox's methods to precache all static content.</p>
  <p>Unfortunately I have severals contents between 5 and 10 MB (audio files) and in the Create React App Service Worker the limit is set to 5MB (previosly 2MB - see <a href="https://github.com/facebook/create-react-app/pull/10048" rel="nofollow noreferrer">here</a>).</p>
  <p>Those files are not precached and indeed i get warnings during the build process:
  <code>/static/media/song.10e30995.mp3 is 5.7 MB, and won't be precached. Configure maximumFileSizeToCacheInBytes to change this limit.</code>.</p>
  <p>Pity that <code>maximumFileSizeToCacheInBytes</code> seems not to be configurable in CRA SW :(</p>
  <p>I cannot decrese the files size because of audio quality requirements.</p>
  <p>I also wrote a custom SW logic to precache external resources from the internet and I thought of adding the audio files there. but the React build process adds an hashcode to the filenames based on their content, so I would need to change the SW code every time I update the audio content, and that's not ideal.</p>
  <p>So my questions are:</p>
  <ul>
  <li>is there any way to force the <code>maximumFileSizeToCacheInBytes</code> limit to a custom value, within a CRA application?</li>
  <li>I was thinking of trying to get the hashcodes after the build process and automatically update the SW code, but is not very convincing to me.</li>
  <li>is there any other solution or method to achieve what I need?</li>
  </ul>
  <p>Here's my SW code (the default CRA code + my custom logic at the end)</p>
  <pre class="lang-js prettyprint-override"><code>import { clientsClaim } from 'workbox-core';
  import { ExpirationPlugin } from 'workbox-expiration';
  import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching';
  import { registerRoute } from 'workbox-routing';
  import { StaleWhileRevalidate } from 'workbox-strategies';
  
  import packageJson from '../package.json';
  
  
  clientsClaim();
  
  // Precache all of the assets generated by your build process.
  // Their URLs are injected into the manifest variable below.
  // This variable must be present somewhere in your service worker file,
  // even if you decide not to use precaching. See https://cra.link/PWA
  precacheAndRoute(self.__WB_MANIFEST);
  
  // Set up App Shell-style routing, so that all navigation requests
  // are fulfilled with your index.html shell. Learn more at
  // https://developers.google.com/web/fundamentals/architecture/app-shell
  const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$');
  registerRoute(
    // Return false to exempt requests from being fulfilled by index.html.
    ({ request, url }) =&gt; {
      // If this isn't a navigation, skip.
      if (request.mode !== 'navigate') {
        return false;
      } // If this is a URL that starts with /_, skip.
  
      if (url.pathname.startsWith('/_')) {
        return false;
      } // If this looks like a URL for a resource, because it contains // a file extension, skip.
  
      if (url.pathname.match(fileExtensionRegexp)) {
        return false;
      } // Return true to signal that we want to use the handler.
  
      return true;
    },
    createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html')
  );
  
  // An example runtime caching route for requests that aren't handled by the
  // precache, in this case same-origin .png requests like those from in public/
  registerRoute(
    // Add in any other file extensions or routing criteria as needed.
    ({ url }) =&gt; url.origin === self.location.origin &amp;&amp; url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
    new StaleWhileRevalidate({
      cacheName: 'images',
      plugins: [
        // Ensure that once this runtime cache reaches a maximum size the
        // least-recently used images are removed.
        new ExpirationPlugin({ maxEntries: 50 }),
      ],
    })
  );
  
  // This allows the web app to trigger skipWaiting via
  // registration.waiting.postMessage({type: 'SKIP_WAITING'})
  self.addEventListener('message', (event) =&gt; {
    if (event.data &amp;&amp; event.data.type === 'SKIP_WAITING') {
      self.skipWaiting();
    }
  });
  
  // Any other custom service worker logic can go here.
  const CUSTOM_PRECACHE_NAME = `custom-precache-v${packageJson.version}`;
  
  const CUSTOM_PRECACHE_URLS = [
   // ... external resources URLs here
  ];
  
  self.addEventListener('install', event =&gt; {
    const now = new Date();
    console.log(`PWA Service Worker adding ${CUSTOM_PRECACHE_NAME} - :: ${now} ::`);
    event.waitUntil(caches.open(CUSTOM_PRECACHE_NAME)
      .then(cache =&gt; {
        return cache.addAll(CUSTOM_PRECACHE_URLS)
          .then(() =&gt; {
            self.skipWaiting();
          });
      }));
  });
  
  // The fetch handler serves responses for same-origin resources from a cache.
  self.addEventListener('fetch', event =&gt; {
    event.respondWith(
      caches.match(event.request)
        .then(resp =&gt; {
  
          // @link https://stackoverflow.com/questions/48463483/what-causes-a-failed-to-execute-fetch-on-serviceworkerglobalscope-only-if
          if (event.request.cache === 'only-if-cached' &amp;&amp; event.request.mode !== 'same-origin') {
            return;
          }
  
          return resp || fetch(event.request)
            .then(response =&gt; {
              return caches.open(CUSTOM_PRECACHE_NAME)
                .then(cache =&gt; {
                  cache.put(event.request, response.clone());
                  return response;
                });
            });
        })
    );
  });
  </code></pre>
  <p>I hope I made myself clear.</p>
  <p>Thanks in advance,
  Francesco</p>