You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
alert("Service Worker active with scope: "+registration.scope);
4274
+
}
4275
+
} catch (error) {
4276
+
alert(`Registration failed with ${error}`);
4277
+
}
4278
+
}
4279
+
};
4280
+
4281
+
registerServiceWorker();
4271
4282
```
4272
4283
4273
4284
[](https://codesandbox.io/p/sandbox/118-implementing-offline-capabilities-with-service-workers-zjm7tx)
@@ -4280,6 +4291,7 @@ if ('serviceWorker' in navigator) {
4280
4291
- First, it checks if the browser supports Service Workers.
4281
4292
- If supported, it registers the Service Worker script (`service-worker.js` - what the script does is outside the scope of this book) using the `register()` method.
4282
4293
- The Service Worker script can intercept network requests, cache assets, and manage offline behavior.
4294
+
- Please turn off your internet and reload the page; it will still load, showing the offline capabilities of the Service Worker.
[](https://codesandbox.io/p/sandbox/120-offline-data-synchronization-5gpt4c)
4361
+
4362
+
-[^120]CodeSandbox: Offline Data Synchronization.
4363
+
4364
+
[^120]:[CodeSandbox: Offline Data Synchronization.](https://tmpq6w.csb.app/), last access: October 13, 2024.
4365
+
4348
4366
- The code above demonstrates how to perform offline data synchronization using a background sync event (`sync` event).
4349
4367
- When a sync event with the tag `sync-data` is triggered, it calls the `syncData()` function.
4350
4368
- Developers can implement custom synchronization logic inside the `syncData()` function to synchronize data with a server or local storage.
0 commit comments