0

I am doing background queue configuration in workbox for "POST" operation. Kindly guide me where to give option for "POST" operation inside 'runtimeCaching' configuration in workbox-config.js

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.

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.

1 Answers1

1

Adding in method: 'POST' should give you the behavior you want:

runtimeCaching: [{
  urlPattern: /api/,
  handler: 'NetworkOnly',
  method: 'POST',
  options: {
    // Configure background sync.
    backgroundSync: {
      name: 'product-bgsync-queue1',
      options: {
        maxRetentionTime: 24 * 60 * 60,
      },
    },
  },
}]
Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167