Unverified Commit affd86f0 authored by Sam Poder's avatar Sam Poder Committed by GitHub

[docs] Update progressive web apps documentation for new service worker syntax (#95431)

We recently rolled out this new syntax for bundling service workers with
Turbopack:

```
await navigator.serviceWorker.register(new URL('../lib/service-workers/1.js', import.meta.url), ...)
```

This PR updates the documentation that previously mentioned service
workers.

---------
Co-authored-by: 's avatarvercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
parent a249dcbc
......@@ -156,10 +156,13 @@ function PushNotificationManager() {
}, [])
async function registerServiceWorker() {
const registration = await navigator.serviceWorker.register('/sw.js', {
scope: '/',
updateViaCache: 'none',
})
const registration = await navigator.serviceWorker.register(
new URL('../lib/service-worker.js', import.meta.url),
{
scope: '/',
updateViaCache: 'none',
}
)
const sub = await registration.pushManager.getSubscription()
setSubscription(sub)
}
......@@ -234,10 +237,13 @@ function PushNotificationManager() {
}, []);
async function registerServiceWorker() {
const registration = await navigator.serviceWorker.register('/sw.js', {
scope: '/',
updateViaCache: 'none',
});
const registration = await navigator.serviceWorker.register(
new URL('../lib/service-worker.js', import.meta.url),
{
scope: '/',
updateViaCache: 'none',
}
)
const sub = await registration.pushManager.getSubscription();
setSubscription(sub);
}
......@@ -544,9 +550,9 @@ VAPID_PRIVATE_KEY=your_private_key_here
### 5. Creating a Service Worker
Create a `public/sw.js` file for your service worker:
Create a `lib/service-worker.js` file for your service worker:
```js filename="public/sw.js"
```js filename="lib/service-worker.js"
self.addEventListener('push', function (event) {
if (event.data) {
const data = event.data.json()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment