Skip to content

Latest commit

 

History

History
 
 

lifecycle

next-pwa - lifecycle and register workflow control example

[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.

Usage

Open in Gitpod

cd examples/lifecycle
pnpm build
pnpm start

Recommended .gitignore

**/public/precache.*.js
**/public/sw.js