Quick answer: Serve your site over HTTPS, link a manifest.json with a name, icons and start_url, and register a service worker that caches your app shell and returns an offline page.
- Create
manifest.jsonwith name, 192px and 512px icons,start_urlanddisplay: standalone. - Link it from every page's
<head>. - Add
sw.jsat the site root to precache the shell and serveoffline.htmlwhen the network fails. - Register the worker from your main script after the page loads.
- Check the Manifest and Service workers sections of the DevTools Application panel, then reload with the network set to Offline.
In this guide
- Before You Start
- What a Progressive Web App Needs
- Step 1: Create a manifest.json That Makes Your App Installable
- Step 2: Register a Service Worker and Cache the App Shell
- Step 3: Add an Offline Page
- Step 4: Test It in Chrome DevTools
- Choose a Caching Strategy for Each Kind of Request
- Ship Updates Without Stale Files
- PWA Features That Bring Users Back
- Performance Budgets and Guardrails
- PWA vs Native vs Hybrid: Which Should You Build?
- Security and Privacy for PWAs
- Testing and Monitoring After Launch
- If It Still Doesn't Work
- Official docs and trusted sources
- Frequently Asked Questions
- Next Steps
Before You Start
- A site you can edit and serve. Plain HTML works, and so does any framework build output.
- HTTPS in production. Service workers only run on HTTPS origins.
http://localhostis allowed for testing. - Two PNG icons, 192×192 and 512×512 pixels.
- Chrome or Edge for the DevTools checks in the test step.
- Time: about an hour for the basic version in this guide.
- Rollback warning: a service worker keeps serving cached files to returning visitors until you ship a new one. Test on localhost or staging first, and know how to push a fixed
sw.js(see "Ship Updates Without Stale Files").
What a Progressive Web App Needs
- Web app manifest (
manifest.json): a small JSON file that tells the browser the app's name, icons, start page and display mode. - HTTPS everywhere: required for service workers and most powerful web APIs.
- Service worker: a script that runs between your page and the network. It handles caching, offline fallbacks and updates.
- Installability: in Chrome, a valid manifest, HTTPS and some user engagement make the app installable and fire the
beforeinstallpromptevent. Chrome no longer requires a service worker for this, but you still need one for offline support. Safari and Firefox do not fire that event; on iOS, users install through Share → Add to Home Screen. - How to check it: Lighthouse removed its PWA category in version 12. Verify the manifest and service worker in the Application panel of Chrome DevTools, and keep Lighthouse for performance, accessibility and best practices.
Step 1: Create a manifest.json That Makes Your App Installable
Save the file below as manifest.json in your site's root folder, next to index.html. Change the names, colours and icon paths to match your app.
- name / short_name: keep
short_nameunder about 12 characters so it fits under the home-screen icon. - icons: provide 192x192 and 512x512 PNGs at minimum.
- start_url: adding
?source=a2hslets you count visits from the installed app in analytics. Add the same URL to the service worker's cached shell, or the installed app shows the offline page when launched without a connection. - display:
standalonehides the browser UI (usefullscreenfor kiosk-style apps). - theme_color / background_color: used for the title bar and the splash screen.
- scope: the paths that belong to the app; keep it no broader than you need.
{
"name": "Acme Notes",
"short_name": "Notes",
"start_url": "/?source=a2hs",
"scope": "/",
"display": "standalone",
"theme_color": "#0f172a",
"background_color": "#ffffff",
"icons": [
{ "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png" }
]
}Then link the file from the <head> of every page with <link rel="manifest" href="/manifest.json">. Open DevTools → Application → Manifest: you should see your app name and both icons. Any missing field or broken icon path is listed there as a warning.
Step 2: Register a Service Worker and Cache the App Shell
The "app shell" is the HTML, CSS and JavaScript that draw your app's frame. Caching it means repeat visits load instantly and the app still opens offline. The code below has two parts, marked by comments:
- The first part, up to the blank line, goes in your main script (
main.js, or whatever file every page already loads). It registers the worker after the page has loaded. - Everything after
// sw.jsgoes in a new file calledsw.jsin the site root. A worker only controls pages at or below its own folder, so/sw.jscontrols the whole site.
// main.js: register after the page has loaded
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js');
});
}
// sw.js
const CACHE = 'app-shell-v1'; // bump the version to ship a new shell
const SHELL = ['/', '/?source=a2hs', '/styles.css', '/app.js', '/offline.html'];
self.addEventListener('install', (event) => {
event.waitUntil(caches.open(CACHE).then((cache) => cache.addAll(SHELL)));
});
self.addEventListener('activate', (event) => {
// Remove caches left over from older versions
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key)))
)
);
});
self.addEventListener('fetch', (event) => {
if (event.request.method !== 'GET') return;
event.respondWith(
caches.match(event.request).then(
(cached) =>
cached ||
fetch(event.request).catch(() =>
event.request.mode === 'navigate' ? caches.match('/offline.html') : Response.error()
)
)
);
});What this worker does:
- install: downloads every file in
SHELLinto a cache namedapp-shell-v1. If any file returns an error, the whole install fails, so check each path exists. - activate: deletes caches from older versions.
- fetch: answers GET requests from the cache first. Anything not cached goes to the network. If the network fails on a page navigation, it shows
/offline.html.
This minimal worker does not add new responses to the cache. For runtime caching of API data and images, see the strategies below or use Workbox.
Step 3: Add an Offline Page
Create offline.html in the site root: a short self-contained page that says the user is offline and links back to /. Keep its styles inline or in styles.css, because only the files in SHELL are guaranteed to be available offline.
Step 4: Test It in Chrome DevTools
- Serve the folder locally, for example by running
python3 -m http.server 8080in the project folder in a terminal, then openhttp://localhost:8080. - Open DevTools (F12) → Application → Service workers. You should see
sw.jswith a status of activated and running. - Under Cache storage, open
app-shell-v1. It should list the four shell files. - In the Network panel, set throttling to Offline and reload. The page should still load. Visit a URL that is not cached and you should get your offline page.
- On desktop Chrome, an install icon appears in the address bar once the manifest is valid. Installing opens the app in its own window.
Choose a Caching Strategy for Each Kind of Request
Pick a strategy per route or asset type rather than one rule for everything:
- App shell: cache-first with a versioned precache list (what Step 2 does).
- API data: stale-while-revalidate, which answers from the cache immediately and refreshes it in the background.
- Images: cache-first with a maximum number of entries and an expiry time.
- Private or fast-changing data: network-only.
- Fallbacks: an offline page for documents and a placeholder for images.
Wrap network calls in timeouts so a slow connection falls back to cached content instead of hanging. Static files with hashed names can also carry long browser-cache headers; see immutable Cache-Control and cache busting in Nginx.
Ship Updates Without Stale Files
Because the shell is served cache-first, visitors keep the old HTML, CSS and JS until a new worker replaces the cache.
- Change
CACHEto a new name, such asapp-shell-v2, every time you deploy new shell files. - Deploy. The browser notices that
sw.jschanged and installs the new worker. - The new worker waits until every tab using the old one is closed, then activates and deletes the old cache.
- To apply updates sooner, listen for the new worker in your page and show a "New version available, refresh" message.
While developing, tick Update on reload in Application → Service workers so you always run the latest sw.js.
PWA Features That Bring Users Back
- Route prefetch: fetch the next likely page's assets while the browser is idle.
- Background sync: queue POST requests made offline and send them when the connection returns. The Background Sync API only exists in Chromium browsers, so in Safari and Firefox replay the queue when the app is next opened or comes back online.
- Push notifications: use sparingly, and ask only after the user has seen value (order updates, saved-search alerts).
- Web Share API: lets users share content through the phone's native share sheet.
Performance Budgets and Guardrails
- Set a budget and enforce it in CI, for example a main bundle under 200KB gzipped, CSS under 100KB, lazy-loaded images and subsetted fonts.
- Measure on real devices: a low-end Android phone and a slow network profile in DevTools show what users feel.
- Code-split routes: do not ship the dashboard code to the landing page.
- Image pipeline: responsive images (
srcset), AVIF/WebP, and long cache lifetimes. - Accessibility: install buttons, toasts and offline banners must work with screen readers.
PWA vs Native vs Hybrid: Which Should You Build?
- Choose a PWA for content sites, marketplaces, SaaS dashboards, media, docs and tools where links, search traffic and one codebase matter most.
- Choose native for deep OS integration, heavy 3D graphics or games, Bluetooth/USB, or long-running background work.
- Choose hybrid when you already have web code but need an app-store listing or a few native APIs.
If you are weighing cross-platform native frameworks instead, read Flutter vs React Native.
Security and Privacy for PWAs
- HTTPS is required; also enable HSTS and a strict Content Security Policy where you can.
- Permissions: request push/notification permission only after the user has seen value.
- Tokens: store them in HttpOnly cookies where your architecture allows; otherwise keep lifetimes short and use refresh flows.
- Patches: ship security fixes quickly and bump the cache version so old files are dropped.
Testing and Monitoring After Launch
- Lighthouse in Chrome DevTools for Performance, Accessibility, Best Practices and SEO. It no longer has a PWA category, so inspect the manifest, service worker and caches in the Application panel.
- Web Vitals: watch LCP, CLS and INP from real users in GA4 or a RUM (real-user monitoring) tool.
- Network profiles: test offline, slow 3G, and DNS/TLS delays.
- Error tracking: capture service worker failures and cache misses, and alert if the install rate drops.
If It Still Doesn't Work
- The service worker never registers. The page is not on HTTPS or localhost, or
/sw.jsreturns 404. Open/sw.jsdirectly in the browser to check it loads. - The worker never activates and no cache appears. One of the files in
SHELLdoes not exist.cache.addAll()fails if any single request fails; fix the path and reload. - Your changes do not show up. The old worker is still serving cached files. Bump
CACHE, deploy, and close all tabs of the site (or tick Update on reload while developing). - No install option appears. Check Application → Manifest for warnings. Common causes are a missing
<link rel="manifest">, wrong icon paths, or icons that are not the stated size. - The offline page never appears.
/offline.htmlis missing fromSHELL, or you tested a request that is not a page navigation (images and API calls getResponse.error()instead).
Official docs and trusted sources
- web.dev PWA guides: web.dev/learn/pwa
- MDN Progressive Web Apps: developer.mozilla.org
- MDN Service Workers: developer.mozilla.org
- Chromium installability criteria: web.dev install criteria
- Apple Safari PWA updates: developer.apple.com/safari
- Workbox (Google) for service workers: developer.chrome.com/docs/workbox
- Lighthouse PWA audits (deprecated): developer.chrome.com
Frequently Asked Questions
What makes a website installable as a PWA?
A valid web app manifest served over HTTPS. The manifest needs a name, 192px and 512px icons, a start_url and a display mode. Chrome also waits for some user engagement before offering the install prompt, and no longer requires a service worker for installability, though you still need one for offline use.
Do PWAs work on iPhone and iPad?
Yes. Safari supports service workers, Add to Home Screen and many web APIs, so the core of a PWA works on iOS. Some APIs are still limited or missing, such as Background Sync, so test the features you rely on on a recent iOS version before you commit.
Can a PWA send push notifications on iOS?
Yes, from iOS 16.4, but only after the user has added the PWA to the Home Screen. On Android and desktop Chrome, web push works from a normal browser tab. On every platform, ask for permission only after the user has seen value, or most people will decline.
Does a PWA need an app store listing?
No. Users install it straight from the browser. If store presence matters for your audience, you can wrap the same PWA with a Trusted Web Activity for Google Play, or use a hybrid wrapper for other stores.
Is Workbox worth using instead of writing my own service worker?
Yes, for most apps beyond the minimal example here. Workbox, Google's service worker library, gives you ready-made caching strategies, precache manifests with automatic versioning, and routing, which avoids many of the stale-cache bugs that hand-written workers run into.
Next Steps
Add the manifest and sw.js from this guide to your site, run the four DevTools checks on localhost, then deploy over HTTPS. If you still need hosting with SSL and a custom domain, follow how to deploy a web app on Hostinger with Namecheap DNS and SSL. Once the basics work, move runtime caching and precaching to Workbox.

