Save files in cache with sw-precache and React

180 Views Asked by At

Does anyone know how I can cache my APP_SHELL files using sw-precache plugin and React?

The application was created with the cra command and I have managed to read my own service-worker. For the build and to take my files I have the following configuration:

module.exports = {
        staticFileGlobs: [
          'build/static/css/**.css',
          'build/static/js/**.js',
          'index.html',
          '/'
        ],
        swFilePath: './build/service-worker.js',
        stripPrefix: 'build/',
        importScripts: (['./service-worker-custom.js']),
        handleFetch: false,
        minify: true,
      }

But I do not know in which part to indicate that I need to cache the APP_SHELL of my PWA.

I have tried to do it from my custom service worker but I can not register the files correctly, I have tried it in this way:

const cacheUrls = [
    '/',
    'build/static/css/**.css',
    'build/static/js/**.js',
    'build/media/**.jpg'
];

const cacheUrls = [
    '/',
    '/index.html',
    '/static/css/',
    '/static/js/',
    '/static/media/',
];


const cacheUrls = [
    '/',
    'build/static/css/*.css',
    'build/static/css/**/*.css',
    'build/static/js/*.js',
    'build/static/js/**/*.js',
    'build/media/**/*.jpg',
    'build/media/*.jpg'
];

But in no way registers the files in cache, only the index.html and the others when reviewing their conditional from the chrome console have the same content as index.html.

Thanks!

0

There are 0 best solutions below