Skip to content
nextjs-pwa logo

Next.js PWA Implementation Guide (2025)

nextjs-pwa

Comprehensive guide for building Progressive Web Apps (PWA) with Next.js using modern 2025 approaches. Use when users need to implement PWA features in Next.js applications including installability, offline support, service workers, web app manifests, caching strategies, push notifications, or co...

mattnigh/skills_collection0installs24stars

SKILL.md

Full skill instructions

Next.js PWA Implementation Guide (2025)

Comprehensive skill for implementing Progressive Web Apps with Next.js using the most current approaches as of 2025.

Quick Start Decision Tree

Follow this decision tree to choose the right implementation:

Need PWA with Next.js?
│
├─ Basic installability only?
│  └─ Use: Native Next.js PWA Support
│     ✓ Zero dependencies
│     ✓ Built-in App Router support
│     ✓ Simple manifest.ts/​json
│     ✗ No offline caching
│
└─ Need offline functionality?
   └─ Use: Serwist Package
      ✓ Advanced caching strategies
      ✓ Service worker management
      ✓ Background sync
      ✓ Push notifications
      ⚠ Requires configuration

Approach 1: Native Next.js PWA Support

Overview

Zero-dependency PWA implementation using Next.js built-in features.

When to Use

  • ✅ Using App Router (/​app directory)
  • ✅ Basic PWA features (installability, manifest)
  • ✅ Don't need complex offline caching
  • ✅ Want zero external dependencies
  • ✅ Following official Next.js recommendations

Key Features

  • Built-in support since Fall 2024 (official PWA guide published)
  • No external packages required
  • Manifest generation via manifest.ts, manifest.json, or manifest.webmanifest
  • Works seamlessly with App Router
  • TypeScript support with MetadataRoute.Manifest type

Limitations

  • No automatic offline support
  • No service worker generation
  • No advanced caching strategies
  • Manual service worker implementation required for offline features

Quick Implementation

1. Create Manifest (app/​manifest.ts):

import type { MetadataRoute } from 'next'

export default function manifest(): MetadataRoute.Manifest {
  return {
    name: 'Your App Name',
    short_name: 'App',
    description: 'Your app description',
    start_url: '/',
    display: 'standalone',
    background_color: '#ffffff',
    theme_color: '#000000',
    icons: [
      {
        src: '/​icon-192.png',
        sizes: '192x192',
        type: 'image/​png',
      },
      {
        src: '/​icon-512.png',
        sizes: '512x512',
        type: 'image/​png',
      },
    ],
  }
}

2. Add Meta Tags (app/​layout.tsx):

export const metadata = {
  manifest: '/​manifest.webmanifest',
  appleWebApp: {
    capable: true,
    statusBarStyle: 'default',
    title: 'Your App Name',
  },
}

3. Deploy with HTTPS (Required for production PWA)


Approach 2: Serwist Package

Overview

Advanced PWA implementation with offline support, caching strategies, and service worker management.

When to Use

  • ✅ Need offline functionality
  • ✅ Advanced caching strategies required
  • ✅ Background sync needed
  • ✅ Push notifications
  • ✅ Complex service worker logic
  • ✅ Fine-grained cache control

Version Information (Updated November 2025)

  • Serwist Latest Stable: 9.2.1+
  • Preview Version: 10.0.0-preview (in development)
  • Breaking Changes: v9.0.0 introduced major API changes (March 2024)
  • Node.js Required: 18.0.0+ (22.x recommended)
  • TypeScript: 5.0.0+

Key Features

  • Automatic service worker generation
  • Pre-caching of static assets
  • Runtime caching strategies (CacheFirst, NetworkFirst, StaleWhileRevalidate)
  • Background sync
  • Push notifications support
  • Offline fallback pages
  • TypeScript support

Turbopack Compatibility (Updated November 2025)

Important Update:

✅ Production builds (next build): Fully compatible - Works normally with Turbopack ⚠️ Development (next dev --turbo): Shows warning but fully functional

Development Warning Solution:

# Option 1: Suppress warning (Recommended for dev)
# Add to .env.local
SERWIST_SUPPRESS_TURBOPACK_WARNING="1"

# Option 2: Use webpack in development
npm run dev -- --webpack

Note: The --webpack flag is NOT required for production builds. Serwist works natively with Turbopack in production.

Installation

npm i @serwist/​next && npm i -D serwist
# or
yarn add @serwist/​next && yarn add -D serwist
# or
pnpm add @serwist/​next && pnpm add -D serwist

Quick Implementation

1. Configure next.config.js:

import withSerwistInit from '@serwist/​next'

const withSerwist = withSerwistInit({
  swSrc: 'app/​sw.ts',
  swDest: 'public/​sw.js',
  cacheOnNavigation: true,
  reloadOnOnline: true,
  disable: process.env.NODE_ENV === 'development', // Optional
})

export default withSerwist({
  // Your Next.js config
})

2. Create Service Worker (app/​sw.ts):

import { Serwist } from 'serwist'

const serwist = new Serwist({
  precacheEntries: self.__SW_MANIFEST,
  skipWaiting: true,
  clientsClaim: true,
  navigationPreload: true,
  runtimeCaching: [
    {
      urlPattern: /^https:\/\/​fonts\.(?:googleapis|gstatic)\.com\/​.*/​i,
      handler: 'CacheFirst',
      options: {
        cacheName: 'google-fonts',
        expiration: {
          maxEntries: 4,
          maxAgeSeconds: 365 * 24 * 60 * 60, // 1 year
        },
      },
    },
    {
      urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/​i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'static-font-assets',
        expiration: {
          maxEntries: 4,
          maxAgeSeconds: 7 * 24 * 60 * 60, // 1 week
        },
      },
    },
    {
      urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/​i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'static-image-assets',
        expiration: {
          maxEntries: 64,
          maxAgeSeconds: 24 * 60 * 60, // 1 day
        },
      },
    },
    {
      urlPattern: /\/​_next\/​image\?url=.+$/​i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'next-image',
        expiration: {
          maxEntries: 64,
          maxAgeSeconds: 24 * 60 * 60, // 1 day
        },
      },
    },
    {
      urlPattern: /\.(?:js)$/​i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'static-js-assets',
        expiration: {
          maxEntries: 32,
          maxAgeSeconds: 24 * 60 * 60, // 1 day
        },
      },
    },
    {
      urlPattern: /\.(?:css|less)$/​i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'static-style-assets',
        expiration: {
          maxEntries: 32,
          maxAgeSeconds: 24 * 60 * 60, // 1 day
        },
      },
    },
    {
      urlPattern: /\/​_next\/​data\/​.+\/​.+\.json$/​i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'next-data',
        expiration: {
          maxEntries: 32,
          maxAgeSeconds: 24 * 60 * 60, // 1 day
        },
      },
    },
    {
      urlPattern: /\/​api\/​.*/​i,
      handler: 'NetworkFirst',
      method: 'GET',
      options: {
        cacheName: 'apis',
        expiration: {
          maxEntries: 16,
          maxAgeSeconds: 24 * 60 * 60, // 1 day
        },
        networkTimeoutSeconds: 10,
      },
    },
    {
      urlPattern: /​.*/​i,
      handler: 'NetworkFirst',
      options: {
        cacheName: 'others',
        expiration: {
          maxEntries: 32,
          maxAgeSeconds: 24 * 60 * 60, // 1 day
        },
        networkTimeoutSeconds: 10,
      },
    },
  ],
})

serwist.addEventListeners()

3. Register Service Worker (app/​layout.tsx):

'use client'

import { useEffect } from 'react'

export default function RootLayout({ children }) {
  useEffect(() => {
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker
        .register('/​sw.js')
        .then((registration) => {
          console.log('Service Worker registered:', registration)
        })
        .catch((error) => {
          console.error('Service Worker registration failed:', error)
        })
    }
  }, [])

  return (
    <html lang="en">
      <body>{children}</​body>
    </​html>
  )
}

4. Update tsconfig.json:

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext", "webworker"],
    "types": ["@serwist/​next/​typings"]
  }
}

5. Create Manifest (same as Native approach)


Breaking Changes: Serwist v9.0.0+

If migrating from older versions, note these critical changes:

1. Import Changes

// ❌ OLD (v8.x and earlier)
import { installSerwist } from '@serwist/​sw'

// ✅ NEW (v9.0.0+)
import { Serwist } from 'serwist'

2. Initialization Changes

// ❌ OLD
const sw = installSerwist({ /​* config */ })

// ✅ NEW
const serwist = new Serwist({ /​* config */ })
serwist.addEventListeners() // Required!

3. Package Consolidation

# ❌ OLD
npm i @serwist/​precaching @serwist/​routing @serwist/​strategies

# ✅ NEW (all in one)
npm i -D serwist

Comparison: Native vs Serwist

FeatureNative Next.jsSerwist
Setup Complexity⭐ Simple⭐⭐⭐ Moderate
Dependencies✅ Zero⚠️ 2 packages
Offline Support❌ Manual✅ Automatic
Caching Strategies❌ None✅ Multiple
Service Worker❌ Manual✅ Auto-generated
App Router Support✅ Native✅ Full
Pages Router Support⚠️ Limited✅ Full
TypeScript✅ Built-in✅ Full
Production Ready✅ Yes✅ Yes
Turbopack Compatible✅ Yes✅ Yes (with env var)

Common Issues & Solutions

Issue 1: Service Worker Not Updating

Solution: Add versioning to your service worker or use skipWaiting: true

Issue 2: Cached Content Not Updating

Solution: Implement proper cache invalidation strategy or reduce maxAgeSeconds

Issue 3: Turbopack Warning in Development

Solution: Add SERWIST_SUPPRESS_TURBOPACK_WARNING="1" to .env.local

Issue 4: HTTPS Required Error

Solution: Deploy to HTTPS domain (localhost works for testing)

Issue 5: Icons Not Showing

Solution: Ensure icons are in public/ directory and manifest paths are correct


Recommendations

For New Projects:

  1. Start with Native Next.js PWA (simple, zero dependencies)
  2. Upgrade to Serwist only when offline features are needed

For Existing Projects:

  1. Migrating from next-pwa? → Use Serwist (direct replacement)
  2. Already have custom service worker? → Keep it or refactor to Serwist
  3. Using Pages Router? → Serwist recommended (better support)

For Production:

  1. ✅ Always use HTTPS
  2. ✅ Test offline functionality thoroughly
  3. ✅ Implement proper error handling
  4. ✅ Monitor service worker updates
  5. ✅ Use appropriate cache strategies for different assets

Resources


Version History

  • November 2025: Updated Serwist version info, Turbopack compatibility clarifications
  • Fall 2024: Native Next.js PWA support officially documented
  • March 2024: Serwist v9.0.0 released with breaking changes
  • 2023: Serwist created as modern alternative to Workbox

Consulte os seguintes arquivos para obter informações completas e atualizadas:

C:\Users\tetu_.claude\skills\nextjs-pwa\references\serwist-implementation.md C:\Users\tetu_.claude\skills\nextjs-pwa\references\native-nextjs-implementation.md C:\Users\tetu_.claude\skills\nextjs-pwa\references\implementation-approaches.md

Last Updated: November 13, 2025

More skills from mattnigh

spring-framework-patterns logo
mattnigh/skills_collection

spring-framework-patterns

Comprehensive Spring Framework and Spring Boot best practices including dependency injection patterns, bean lifecycle and scopes, REST API development, Spring Data JPA, service layer design, Spring Security, testing strategies, caching, AOP, async processing, error handling, and common anti-patte...

24 0
View

TypeScript厳格モードによる型安全性設計を専門とするスキル。 📖 参照書籍: - 『Effective TypeScript』(Dan Vanderkam): 型設計 📚 リソース参照: - `resources/Level1_basics.md`: レベル1の基礎ガイド - `resources/Level2_intermediate.md`: レベル2の実務ガイド - `resources/Level3_advanced.md`: レベル3の応用ガイド - `resources/Level4_expert.md`: レベル4の専門ガイド - `resources/di...

24 0
View
deploying-cloud-k8s logo
mattnigh/skills_collection

deploying-cloud-k8s

Deploys applications to cloud Kubernetes (AKS/GKE/DOKS) with CI/CD pipelines. Use when deploying to production, setting up GitHub Actions, troubleshooting deployments. Covers build-time vs runtime vars, architecture matching, and battle-tested debugging.

24 0
View
moai-alfred-agent-guide logo
mattnigh/skills_collection

moai-alfred-agent-guide

19-agent team structure, decision trees for agent selection, Haiku vs Sonnet model selection, and agent collaboration principles. Use when deciding which sub-agent to invoke, understanding team responsibilities, or learning multi-agent orchestration.

24 0
View
mermaid-diagram-generator logo
mattnigh/skills_collection

mermaid-diagram-generator

Converts architecture descriptions, module specs, or workflow docs into Mermaid diagrams. Use when visualizing brick module relationships, workflows (DDD, investigation), or system architecture. Supports: flowcharts, sequence diagrams, class diagrams, state machines, entity relationship diagrams,...

24 0
View
pre-flight-check logo
mattnigh/skills_collection

pre-flight-check

INVOKE FIRST before any code work. Validates git workflow (branch, issue, worklog) and checks approach. Use at START of every task and END before completing. Prevents skipped steps.

24 0
View
browser-dev-tools logo
mattnigh/skills_collection

browser-dev-tools

This skill should be used when working with browser-rendered artifacts (i.e. Bun, React/React Native) to proactively validate that development work on localhost is being built appropriately and to support debugging browser-rendered content. Use this skill after making frontend changes to verify t...

24 0
View
lead-dev logo
mattnigh/skills_collection

lead-dev

Lead Développeur - Coordination technique opérationnelle, code review, mentoring et livraison. Pair de web-dev-process au niveau OPÉRATIONS.

24 0
View
worker-monitor logo
mattnigh/skills_collection

worker-monitor

Monitor Docker workers, RQ queue health, and auto-scale workers (max 4). Use when: checking job progress, monitoring queue depth, scaling workers up/down, diagnosing slow processing, or waiting for jobs to complete. Referenced by data-quality skill during reprocessing.

24 0
View
quality-advisor logo
mattnigh/skills_collection

quality-advisor

Proactive quality guidance system that monitors artifact creation and provides real-time feedback on documentation quality

24 0
View
bump-version logo
mattnigh/skills_collection

bump-version

This skill should be used when the user wants to bump the version number in the workspace. It updates versions across all pyproject.toml files (root, tde, and tda packages) and the CHANGELOG.md to keep them synchronized.

24 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View