Search code examples
reactjsservice-workersw-precache

React service worker add files to cache


Building the first React app based on create-react-app. It already have a service-worker.js in production build, but I need to add couple JavaScript (workers) files manually. These files are not included in the HTML and service worker do not cache them.

What is the correct way to add files to service worker cache list?


Solution

  • Because I did not find better solution, I decided to modify the file node_modules/react-scripts/config/webpack.config.prod.js

    Find line

    new SWPrecacheWebpackPlugin({
    

    and paste below

    mergeStaticsConfig: true,
    stripPrefix: './public/',
    staticFileGlobs: ['./public/./js/jimp.min.js', './public/./js/jimp-worker.js'],