• Home
    Blog
    Poetry
    About
    Contact
  • Get Started

How to Build a Progressive Web App (PWA) with Next.js and React? Step By Step Guide

avatar

Gautam Patoliya

@mr_gattu_07

1 hour Read

June 29, 2024


2 Claps

Frontend Development
Mobile Development
Web Development

Progressive Web Apps (PWAs) combine the best of web and mobile applications, offering benefits like offline access, fast loading times, and a native app-like experience. In this blog post, we'll walk you through building a PWA using Next.js and React.

Table of Contents


  1. Introduction to PWAs
  2. Setting Up the Next.js Project
  3. Creating the React Components
  4. Adding PWA Features
  5. Testing the PWA
  6. Deploying the PWA
  7. Conclusion



1. Introduction to PWAs


PWAs provide several key benefits:


  • Offline Access: Ability to work without an internet connection.
  • Performance: Faster load times and smoother user experiences.
  • Engagement: Features like push notifications and home screen installation.
  • Reach: Accessible through web browsers on any device.


2. Setting Up the Next.js Project


First, ensure you have Node.js installed. Create a new Next.js project:


npx create-next-app pwa-nextjs
cd pwa-nextjs
npm install


3. Creating the React Components


Create basic React components for your PWA. In the pages directory, create index.js:


import React from 'react';

export default function Home() {   return (     <div>       <h1>Welcome to my PWA</h1>       <p>This is a Progressive Web App built with Next.js and React.</p>     </div>   ); }


4. Adding PWA Features


Step 4.1: Install PWA Dependencies


Install the necessary packages to add PWA capabilities:


npm install next-pwa


Step 4.2: Configure Next.js for PWA


Create a next.config.js file at the root of your project:


const withPWA = require('next-pwa');

module.exports = withPWA({   pwa: {     dest: 'public',   }, });


Step 4.3: Add Service Worker


Create a public directory at the root of your project. Inside public, create a manifest.json file:


{
  "name": "Next.js PWA",
  "short_name": "NextPWA",
  "description": "A Progressive Web App built with Next.js and React",
  "start_url": "/",
  "display": "standalone",
  "background_color": "#ffffff",
  "theme_color": "#000000",
  "icons": [
    {
      "src": "/icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "/icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ]
}


Add your icons (icon-192x192.png and icon-512x512.png) to the public directory.


5. Testing the PWA


Run your application:


npm run dev


Open your browser and navigate to http://localhost:3000. Use Chrome DevTools to audit your site as a PWA:


  1. Open Chrome DevTools.
  2. Go to the "Application" tab.
  3. Check the "Service Workers" section to see if the service worker is registered.
  4. Use the "Lighthouse" tab to run an audit and see your PWA score.


6. Deploying the PWA


To deploy your PWA, you can use Vercel, which offers seamless integration with Next.js projects:


npm install -g vercel
vercel


Follow the prompts to deploy your PWA to Vercel.


7. Conclusion


Congratulations! You've built and deployed a Progressive Web App using Next.js and React. PWAs offer a powerful way to create fast, reliable, and engaging user experiences on the web. Keep exploring and adding more features to enhance your PWA.


Tags:
JavaScript
React
Next.js
Solution
How to
Question
Basic to Advance
Beginner to Expert
Progressive Web Apps (PWA)

Comments

(2)


LINKS

  • Home
  • Blog
  • Pricing
  • About
  • Contact

SOCIAL LINKS

  • Email
  • Instagram
  • LinkedIn

LEGAL

  • Terms and Conditions
  • Privacy Policy

Copyright © 2025 iThoughtSpace. All rights reserved.

avatar

jay harpal

・ 1y

NICE ❤️

avatar

jay harpal

・ 1y

Very Good Blog ❤️👍

avatar

Gautam Patoliya

・ 1y

Thanks 😊✨

D

DeepPoradiya

・ 1y

hello

avatar

jay harpal

・ 1y

Hii gautam