Is there a configurable way to batch workbox-background-sync requests in vite-pwa plugin

17 Views Asked by At

How can we replay the background sync requests in batches instead of individual requests replay?

Configured the vite-pwa as per the documentation When the request fails it is automatically added to the background sync queue and then the browser triggers the sync event and requests are replayed one by one.

I just want to know if there is a way to replay the requests in batches.

1

There are 1 best solutions below

0
Geetika Paul On

the onSync option can be used to add custom replay request logic.

"A function that gets invoked whenever the 'sync' event fires. The function is invoked with an object containing the queue property (referencing this instance), and you can use the callback to customize the replay behavior of the queue. When not set the replayRequests() method is called."

Ex: workbox: { runtimeCaching: [{ handler: 'NetworkOnly', urlPattern: //api/./.json/, method: 'POST', options: { backgroundSync: { name: 'myQueueName', options: { maxRetentionTime: 24 * 60, onSync: async ({ queue }) => { // add batch sync requst logic here } }, } } }] }