React as a PWA
{
"name": "App Name",
"short_name": "Short",
"start_url": "/",
"display": "standalone",
"theme_color": "#000000",
"icons": [
{ "src": "icon-192.png", "sizes": "192x192", "type": "image/png" }
]
}
The Web App Manifest
manifest.json is a JSON file describing your app's name, icons, theme color, and how it should look when installed (like fullscreen or standalone).
Browsers use this file to decide whether to offer 'Add to Home Screen' and how the installed app should appear.
Example: manifest.json Content
$ cat public/manifest.json
{
"short_name": "MyApp",
"name": "My React App",
"icons": [
{ "src": "icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "icon-512.png", "sizes": "512x512", "type": "image/png" }
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
⚠️ Run this in your own terminal or Node.js environment.
Adding a Service Worker for Offline Support
A service worker is a script that runs separately from your page, able to intercept network requests and serve cached responses when the network is unavailable.
This is what enables an app to keep working (at least partially) offline, a defining feature of a true PWA.
Example: Adding a Service Worker for Offline Support
// Run in your local React project (npm install required)
// vite.config.js (using vite-plugin-pwa)
import { VitePWA } from 'vite-plugin-pwa';
export default {
plugins: [VitePWA({ registerType: 'autoUpdate' })],
};
⚠️ This example uses an npm package with no CDN build available here — run this in your local React project.
Testing PWA Behavior
Chrome DevTools' Application tab lets you inspect the registered service worker, simulate offline mode, and verify the manifest is correctly recognized — essential for confirming your PWA setup actually works before relying on it in production.
- Forgetting the manifest.json file, which is what lets a browser offer 'Add to Home Screen' at all.
- Not testing offline behavior, assuming the service worker 'just works' without actually verifying cached content loads without a connection.
- Caching content too aggressively, causing users to see stale content long after a new deployment.
- A Progressive Web App (PWA) is a web app that can be installed and behave more like a native app, including offline support.
- A manifest.json file describes the app's name, icons, and display mode for installation.
- A service worker is a background script that can cache assets and serve them even when offline.
- Vite and Create React App both offer PWA plugins/templates to set most of this up automatically.
Service workers and installability supported in all modern browsers (notably limited support in older iOS Safari versions historically, though modern versions support much of it).
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first:
- Why Performance Matters
- Optimizing with React.memo
- Avoiding Unnecessary Re-renders
- Using the React Profiler
- Analyzing Bundle Size
- Image Optimization Techniques
- React as a PWA
- Creating a Production Build
- Environment Variables in React
- Deploying to Netlify
- Deploying to Vercel
- Basic CI/CD for React Apps
- SEO Basics for React SPAs