1

有谁知道我如何使用 sw-precache 插件和 React 缓存我的 APP_SHELL 文件?

该应用程序是使用 cra 命令创建的,我已经设法阅读了我自己的 service-worker。对于构建和获取我的文件,我有以下配置:

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,
      }

但我不知道在哪部分表明我需要缓存我的 PWA 的 APP_SHELL。

我试图从我的自定义服务工作者那里做到这一点,但我无法正确注册文件,我已经尝试过这种方式:

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'
];

但绝不会在缓存中注册文件,只有 index.html 和其他在从 chrome 控制台查看条件时具有与 index.html 相同的内容。

谢谢!

4

0 回答 0