workbox-background-sync

A helper library that queues specified requests if they fail over network. Later it uses the Background Sync API to replay these queued requests when the network state has changed.

The main use of this module will be instantiating a new QueuePlugin and passing it to a RequestWrapper, as shown in the first example below.

Example

Using the QueuePlugin class in a service worker.

let bgQueue = new workbox.backgroundSync.QueuePlugin();
const requestWrapper = new workbox.runtimeCaching.RequestWrapper({
  plugins: [bgQueue],
});

const route = new workbox.routing.RegExpRoute({
  regExp: new RegExp('^http://localhost:3000/__echo/counter'),
  handler: new workbox.runtimeCaching.NetworkOnly({requestWrapper}),
});

const router = new workbox.routing.Router();
router.registerRoute({route});

Classes

Queue
QueuePlugin