-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v3 - trouble getting Background Sync to work #1222
Comments
Hello @DavidScales—Sorry that you're running into issues. I believe your first issues, regarding the definition of Regarding your second attempt, I believe that failure is due to It looks like https://developers.google.com/web/tools/workbox/modules/workbox-background-sync needs a couple of changes, so assuming you're able to get things working with those tweaks, we could repurpose this bug to track those changes. |
This issue tracks a better error message for the first use case: #1223 Incoming PR for docs fix. |
No worries, thanks for the explanation @jeffposnick, that make sense. Switching to The updated code: const bgSyncPlugin = new workbox.backgroundSync.Plugin('dashboardr-queue');
const networkOnlyStrategy = new workbox.strategies.NetworkOnly({
plugins: [bgSyncPlugin],
});
workbox.routing.registerRoute(
'http://localhost:8081/api/add',
args => {
console.log('API hit');
return networkOnlyStrategy.handle(args);
},
'POST'
); does store the failed request in IndexedDB (and appears to be syncing once online) 👍 I was still having issues using const bgSyncPlugin = new workbox.backgroundSync.Plugin('dashboardr-queue');
const networkOnlyStrategy = new workbox.strategies.NetworkOnly({
plugins: [bgSyncPlugin],
});
const route = new workbox.routing.Route(
({url}) => url.pathname === '/api/add',
networkOnlyStrategy,
'POST'
);
workbox.routing.registerRoute(route); |
@DavidScales just to confirm you are happy with this being closed? Nothing remains to be done right? |
@gauntface yes, thanks! |
@jeffposnick What is the reasoning behind not supporting POST requests for the caching strategies? Forgive my ignorance, but it would seem that caching the response from POST requests would be a very common use case. |
@garviand, that's part of the Cache Storage API specification. See 5.4.4, step 3.2:
I believe the rationale is that POST and PUT requests are traditionally used to make non-reversable changes to server-controlled resources, and a scenario in which you bypass the server and respond with a previously cached response would not meet developers' expectations. |
Makes a lot of sense, thank you. |
Library Affected:
workbox-sw, workbox-backgroundSync
Issue or Feature Request Description:
I'm having some trouble setting up background sync with v3.
I started with the alpha 5 build & the code from the background sync guide:
On registration I get an error:
Uncaught ReferenceError: Route is not defined
.So I tried switching to another signature that avoids the
Route
object:but this is logging another error:
On the hope of an unpublished patch I built the Workbox packages directly from source & tried using those instead of the CDN, but no luck.
I understand from previous issues in sw-precache that the Cache API doesn't support POST, and that the background sync plugin should be working around that by using IndexedDB. Any ideas?
Notes:
The text was updated successfully, but these errors were encountered: