【问题标题】:how to configure runtimeCaching for POST operations in workbox-config.js如何在 workbox-config.js 中为 POST 操作配置 runtimeCaching
【发布时间】:2019-06-05 02:49:19
【问题描述】:

我正在工作箱中为“POST”操作进行后台队列配置。请指导我在 workbox-config.js 中的“runtimeCaching”配置中为“POST”操作提供选项的位置

module.exports = {
  "globDirectory": "dist/",
  "globPatterns": [
    "**/*.{txt,ico,html,js,css}"
  ],
  "swDest": "dist\\sw.js",
  runtimeCaching: [{
    urlPattern: /api/,
    handler: 'NetworkOnly',
    options: {
      // Configure background sync.
      backgroundSync: {
        name: 'product-bgsync-queue1',
        options: {
          maxRetentionTime: 24 * 60 * 60,
        },
      },
    },
  }]
};

以上代码为 dist/sw.js 中的“GET”生成默认配置。

workbox.routing.registerRoute(/api/,
new workbox.strategies.NetworkOnly({  
   plugins:[  
      new workbox.backgroundSync.Plugin("product-bgsync-queue1",
      {  
         maxRetentionTime:86400
      }      )
   ]
}),
'GET');

请指导如何为“POST”操作生成相同的配置。

【问题讨论】:

    标签: workbox background-sync


    【解决方案1】:

    添加method: 'POST' 应该会给你想要的行为:

    runtimeCaching: [{
      urlPattern: /api/,
      handler: 'NetworkOnly',
      method: 'POST',
      options: {
        // Configure background sync.
        backgroundSync: {
          name: 'product-bgsync-queue1',
          options: {
            maxRetentionTime: 24 * 60 * 60,
          },
        },
      },
    }]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多