From 112812dead4eb947b944153baa66512241d6dff0 Mon Sep 17 00:00:00 2001 From: Matt Gaunt Date: Mon, 29 Jan 2018 12:00:16 -0800 Subject: [PATCH] Adding plugin usage to module guide --- .../modules/workbox-background-sync.md | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/content/en/tools/workbox/modules/workbox-background-sync.md b/src/content/en/tools/workbox/modules/workbox-background-sync.md index 73a5a7cdfa2..36c6cb135d5 100644 --- a/src/content/en/tools/workbox/modules/workbox-background-sync.md +++ b/src/content/en/tools/workbox/modules/workbox-background-sync.md @@ -3,7 +3,7 @@ book_path: /web/tools/workbox/_book.yaml description: The module guide for workbox-background-sync. {# wf_blink_components: N/A #} -{# wf_updated_on: 2017-12-01 #} +{# wf_updated_on: 2018-01-29 #} {# wf_published_on: 2017-11-27 #} # Workbox Background Sync {: .page-title } @@ -32,6 +32,26 @@ BackgroundSync. ## Basic Usage +The easiest way to use Background Sync is to use the `Plugin` that will +automatically Queue up failed requests and retry them for future `sync` +events. + +```javascript +const bgSyncPlugin = new workbox.backgroundSync.Plugin('myQueueName', { + maxRetentionTime: 24 * 60 * 60 * 1000 // Retry for max of 24 Hours +}); + +workbox.routing.registerRoute( + /\/api\/.*\/*.json/, + workbox.strategies.networkOnly({ + plugins: [bgSyncPlugin] + }), + 'POST' +); +``` + +## Advanced Usage + Workbox Background Sync gives you a `Queue` class, which you can instantiate and then add failed requests to. The failed requests are stored in