Next.js provides an excellent foundation for Progressive Web Apps by handling server-side rendering, static generation, and API routes out of the box. This tutorial walks through building a PWA with Next.js from project setup through production deployment, covering service worker integration, offline support, and installability.
Project Setup
Start with a fresh Next.js project and add the PWA dependencies:
Configure next-pwa in your Next.js config:
Web App Manifest
Create the manifest file in the public directory:
Reference the manifest and add PWA meta tags in your root layout:
Install Prompt Component
Build a component that handles the PWA install prompt:
Offline Fallback Page
Create a dedicated offline page that the service worker serves when the network is unavailable:
Add the offline page to your next-pwa configuration:
Push Notifications
API Route for Push Subscription
Client-Side Push Registration
Need a second opinion on your mobile/frontend architecture?
I run free 30-minute strategy calls for engineering teams tackling this exact problem.
Book a Free CallOffline Data with IndexedDB
Build a hook for offline-capable data fetching:
Using the Offline Data Hook in a Page
Offline Form Submission
Handle form submissions that work offline:
Testing the PWA
Lighthouse Audit
Run a Lighthouse PWA audit after building:
Integration Tests
Deployment to Vercel
Add the necessary headers in vercel.json:
Conclusion
Next.js simplifies PWA development by handling the build pipeline, routing, and API layer while next-pwa manages service worker generation and caching strategies. The App Router's server components work seamlessly with PWA patterns — server-rendered pages get cached by the service worker on first visit, providing instant subsequent loads.
The combination of Next.js metadata API for manifest and meta tags, React hooks for install prompts and offline data, and IndexedDB for client-side persistence creates a PWA that rivals native app experiences. Start with the core features (manifest, service worker, offline fallback) and incrementally add push notifications and background sync as your user base grows.