Gruntjs 使用配置了runtimeCaching的sw precache不会加载sw工具箱

Gruntjs 使用配置了runtimeCaching的sw precache不会加载sw工具箱,gruntjs,service-worker,progressive-web-apps,sw-precache,sw-toolbox,Gruntjs,Service Worker,Progressive Web Apps,Sw Precache,Sw Toolbox,根据sw precache文档(包括sw precache的运行时缓存配置),sw precache本身应负责包括用于动态内容运行时缓存的sw工具箱。我已经尝试将其与sw precache的CLI以及grunt sw precache一起使用。我对Grunt的配置如下: grunt.initConfig({ 'sw-precache': { build: { baseDir: './public', workerFileName: 'service-worker.js',

根据sw precache文档(包括sw precache的运行时缓存配置),sw precache本身应负责包括用于动态内容运行时缓存的sw工具箱。我已经尝试将其与sw precache的CLI以及grunt sw precache一起使用。我对Grunt的配置如下:

grunt.initConfig({
'sw-precache': {
  build: {
    baseDir: './public',
    workerFileName: 'service-worker.js',
    appendTimestamp: true,
    cacheId: 'cnbc-polymer-cache-20',
    clientsClaim: true,
    directoryIndex: 'index.html',
    navigateFallback: 'index.html',
    skipWaiting: true,
    maximumFileSizeToCacheInBytes: (1024000 * 20),
    staticFileGlobs: [
      '/src/**/*',
      '/index.html',
      '/manifest.json',
      '/bower_components/**/*',
      '/images/**/*.*',
      '/favicon.ico'
    ],
    verbose: true,
    runtimeCaching: [{
        urlPattern: /franchise/,
        handler: 'cacheFirst',
        options: {
          debug: true,
          cache: {
            maxEntries: 10,
            name: 'franchise-cache',
            maxAgeSeconds: 180
          }
        }
      }, {
        urlPattern: /story/,
        handler: 'cacheFirst',
        options: {
          debug: true,
          cache: {
            maxEntries: 10,
            name: 'story-cache',
            maxAgeSeconds: 180
          }
        }
      }]
  }
}
}))

在尝试使用CLI时,我使用了以下sw-precache-config.js:

module.exports = {
    baseDir: './public',
    workerFileName: 'service-worker.js',
    appendTimestamp: true,
    cacheId: 'cnbc-polymer-cache-20',
    clientsClaim: true,
    directoryIndex: 'index.html',
    navigateFallback: 'index.html',
    skipWaiting: true,
    maximumFileSizeToCacheInBytes: (1024000 * 20),
    staticFileGlobs: [
        '/src/**/*',
        '/index.html',
        '/manifest.json',
        '/bower_components/**/*',
        '/images/**/*.*',
        '/favicon.ico'
    ],
    verbose: true,
    runtimeCaching: [{
        urlPattern: /franchise/,
        handler: 'cacheFirst',
        options: {
            debug: true,
            cache: {
                maxEntries: 10,
                name: 'franchise-cache',
                maxAgeSeconds: 180
          }
        }
      }, {
          urlPattern: /story/,
          handler: 'cacheFirst',
          options: {
              debug: true,
              cache: {
                  maxEntries: 10,
                  name: 'story-cache',
                  maxAgeSeconds: 180
              }
          }
      }]
};
除了runtimeCaching选项之外的所有配置选项都将应用于生成的service-worker.js文件

My package.json配置为使用sw precache的“^4.2.3”和sw toolbox的“^3.4.0”


我没有看到其他人对这个问题发表评论。任何人都可以对sw precache无法遵守我的运行时缓存选项的问题发表评论吗?

请检查并确保您已经这样做了

  • 可以使用以下命令安装grunt sw precache:

    $npm安装grunt sw precache--保存开发人员

  • 通过将以下内容添加到您的
    Gruntfile
    ,启用
    grunt-sw-precache

    grunt.loadNpmTasks('grunt-sw-precache')

然后,您可能希望尝试使用
处理程序:“networkFirst”
而不是
处理程序:“cacheFirst”

如本文所述,

尝试通过从网络获取来处理请求。如果成功,将响应存储在缓存中。否则,请尝试从缓存中完成请求。这是用于基本直通式缓存的策略


您可以访问此网站,了解如何以及为什么一起使用
sw precache
sw toolbox
库的更多信息,以及有关缓存策略的更多信息。

请检查并确保您已经这样做

  • 可以使用以下命令安装grunt sw precache:

    $npm安装grunt sw precache--保存开发人员

  • 通过将以下内容添加到您的
    Gruntfile
    ,启用
    grunt-sw-precache

    grunt.loadNpmTasks('grunt-sw-precache')

然后,您可能希望尝试使用
处理程序:“networkFirst”
而不是
处理程序:“cacheFirst”

如本文所述,

尝试通过从网络获取来处理请求。如果成功,将响应存储在缓存中。否则,请尝试从缓存中完成请求。这是用于基本直通式缓存的策略


您可以访问此网站,了解如何以及为什么一起使用
sw-precache
sw-toolbox
库的更多信息,以及有关缓存策略的更多信息。

遗憾的是
grunt-sw-precache
不依赖于最新的sw-precache,它会导致
运行时缓存
选项和其他选项改进了sw precache如何正确处理请求等问题,从而避免丢失


我复制了回购协议并做了必要的修改。我无意将此发布到npm,而是作为一个临时解决方案(请参考您的package.json中我的github repo!)

遗憾的是,
grunt-sw-precache
并不依赖于最新的sw-precache,这会导致
runtimeCaching
选项和其他改进,如sw-precache如何正确处理请求指示等


我复制了回购协议并做了必要的修改。我无意将此发布到npm,但作为一个临时解决方案(请参考您的package.json中我的github repo!)

我已经安装了grunt sw precache。问题是创建的service-worker.js文件根本不包含任何运行时缓存代码。软件工具箱既不直接包含,也不由importScripts包含。服务工作者文件中没有生成的toolbox.router.get(…)调用。生成的文件中只包含预缓存逻辑。我已经安装了grunt sw precache。问题是创建的service-worker.js文件根本不包含任何运行时缓存代码。软件工具箱既不直接包含,也不由importScripts包含。服务工作者文件中没有生成的toolbox.router.get(…)调用。生成的文件中只包含预缓存逻辑。