[TOC]
This example demonstrates how to use next-pwa
to turn a Next.js
-based web app into a PWA easily.
It shows how to control the service worker registration workflow (instead of automatically registering the service worker) and add an event listener to handle the lifecycle events. It gives you more control over the PWA lifecycle. The key here is to set register
in your withPWAInit
config in next.config.js
to false
then call window.workbox.register()
manually to register the generated service worker.
This example also demonstrates how to prompt the user to reload the page when a new version is available.
cd examples/lifecycle
pnpm build
pnpm start
**/public/precache.*.js
**/public/sw.js