
Progressive web apps (PWAs) combine the reach of the web with the experience of native mobile apps. They load quickly, work offline or on unreliable networks, can be installed on a phone's home screen or a desktop, and can even send push notifications. React is an excellent foundation for building PWAs thanks to its component model and rich ecosystem. In this guide you will learn how to create a progressive web app in React, from project setup to service workers, caching strategies, installability, and deployment.
Build High-Performance PWAs with AAMAX.CO
Creating a PWA that is fast, reliable, and delightful requires careful attention to caching, performance, and user experience. AAMAX.CO is a full service digital marketing company that offers web development, digital marketing, and SEO services worldwide. Their engineers build React-based progressive web apps that feel native, work offline, and engage users with features like push notifications and background sync. They help businesses deliver app-like experiences without the cost and complexity of separate iOS and Android development.
What Makes an App Progressive?
A PWA is a web application that meets a few key criteria:
- It is served over HTTPS for security.
- It includes a web app manifest describing its name, icons, colors, and display mode.
- It registers a service worker that controls network requests and enables offline functionality.
- It is responsive and works on any device.
When these requirements are met, browsers allow users to install the app, and it can launch in its own window like a native app.
Step 1: Create a React Project with Vite
Create React App has been deprecated, so modern projects typically start with Vite:
npm create vite@latest my-pwa -- --template reactcd my-pwanpm installVite offers fast development builds and an excellent plugin ecosystem, including first-class PWA support.
Step 2: Install the PWA Plugin
The vite-plugin-pwa package generates a service worker and manifest using Workbox, Google's library for service worker strategies:
npm install -D vite-plugin-pwaStep 3: Configure the Manifest and Service Worker
Update vite.config.js:
import { defineConfig } from "vite";import react from "@vitejs/plugin-react";import { VitePWA } from "vite-plugin-pwa";export default defineConfig({ plugins: [ react(), VitePWA({ registerType: "autoUpdate", manifest: { name: "My Progressive App", short_name: "MyPWA", start_url: "/", display: "standalone", background_color: "#fff8ee", theme_color: "#510900", icons: [ { src: "/icon-192.png", sizes: "192x192", type: "image/png" }, { src: "/icon-512.png", sizes: "512x512", type: "image/png" }, { src: "/icon-512-maskable.png", sizes: "512x512", type: "image/png", purpose: "maskable" } ] }, workbox: { globPatterns: ["**/*.{js,css,html,png,svg,woff2}"] } }) ]});Place the icon files in the public folder. The standalone display mode removes browser UI so the app feels native.
Step 4: Understand Caching Strategies
Service workers intercept network requests and decide how to respond. Workbox supports several strategies:
- Cache First: serve from cache, falling back to the network. Ideal for fonts, images, and static assets.
- Network First: try the network, falling back to cache when offline. Ideal for frequently updated API data.
- Stale While Revalidate: serve cached content instantly while fetching an update in the background. Great for content that changes occasionally.
Configure runtime caching rules in the workbox.runtimeCaching option to apply these strategies to specific URL patterns.
Step 5: Handle Offline States in React
Let users know when they are offline with a simple hook:
import { useSyncExternalStore } from "react";const subscribe = cb => { window.addEventListener("online", cb); window.addEventListener("offline", cb); return () => { window.removeEventListener("online", cb); window.removeEventListener("offline", cb); };};export const useOnline = () => useSyncExternalStore(subscribe, () => navigator.onLine);Display a banner when offline and queue user actions for later. Workbox's background sync can retry failed requests when the connection returns.
Step 6: Add an Install Prompt
Browsers fire a beforeinstallprompt event when your app is installable. Capture it and show a custom install button at a meaningful moment, such as after a user completes a key action, rather than immediately on page load. On iOS, provide instructions for adding the app via the Share menu.
Step 7: Enable Update Notifications
When you deploy a new version, the service worker updates in the background. Use the plugin's useRegisterSW hook to notify users that new content is available and offer a refresh button, ensuring they always run the latest version.
Step 8: Add Push Notifications
Push notifications re-engage users with timely updates. Request permission only after users understand the value, subscribe them with the Push API, and send messages from your server using the Web Push protocol. Push requires a back-end service, which professional web application development can design securely.
Step 9: Test and Audit
Build and preview the production version with npm run build and npm run preview, since service workers usually do not run in development mode. Use Chrome DevTools' Application panel to inspect the manifest, service worker, and caches, and simulate offline mode. Run Lighthouse to verify PWA criteria, performance, and accessibility.
Step 10: Deploy Over HTTPS
Deploy to a platform that provides HTTPS by default, such as Vercel, Netlify, or Firebase Hosting. Make sure your server sends correct cache headers for the service worker file so updates propagate quickly. Reliable website development workflows include automated builds and deployments for every change.
PWA Design Best Practices
Design an app shell that loads instantly, use skeleton screens instead of spinners, ensure touch-friendly controls, and provide clear offline messaging. Consistent branding through your theme color, icons, and splash screen makes the installed experience feel polished.
Conclusion
Creating a progressive web app in React involves setting up a Vite project, adding a manifest and service worker with vite-plugin-pwa, choosing smart caching strategies, handling offline states, and encouraging installation. Add update notifications and push messaging for deeper engagement, test with Lighthouse, and deploy over HTTPS. The result is a fast, reliable, installable app that reaches users on every platform from a single codebase.