简体   繁体   English

如何在workbox-config.js中为POST操作配置runtimeCaching

[英]how to configure runtimeCaching for POST operations in workbox-config.js

I am doing background queue configuration in workbox for "POST" operation. 我正在工作箱中进行后台队列配置以进行“POST”操作。 Kindly guide me where to give option for "POST" operation inside 'runtimeCaching' configuration in workbox-config.js 请指导我在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,
        },
      },
    },
  }]
};

Above code produce default configuration for "GET" in dist/sw.js. 上面的代码在dist / sw.js中生成“GET”的默认配置。

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

Kindly guide how to generate same configuration for "POST" operation. 请指导如何为“POST”操作生成相同的配置。

Adding in method: 'POST' should give you the behavior you want: 添加method: 'POST'应该为您提供所需的行为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM