PWA in practice

A PWA is a website with three extras: a manifest that tells the phone how to look as an app, a service worker that can answer without a network and receive push, and HTTPS. Here is the smallest version that works, and what we have learned running PWAs in production.

Last checked:

On this pageWhat this page covers
  1. What we run as PWAs ourselves
  2. Requirements for installing
  3. A service worker that doesn't show stale pages
  4. Push on iPhone: only from the home screen, only after a tap
  5. Offline and the EU: what you can count on

What we run as PWAs ourselves

Our own product bkg.dk has a PWA with web push for salon staff. It has been in production since 2 November 2026; an earlier prototype in Django never went live. Our own product cbot.dk has its dashboard as a plain-JavaScript PWA, with no framework. And the owner’s internal assistant has its board as a PWA, while the morning brief arrives in Telegram at 07:30.

What they share: the users already know us, they use the tool every day, and none of them need features only a native app has. That is where a PWA gives the most for the money.

Requirements for installing

Chrome only offers installation when the site runs over HTTPS and has a manifest with name or short_name, icons of 192 and 512 pixels, start_url and a display value such as standalone. The user must also have clicked the page and viewed it for at least 30 seconds. On iPhone there is no automatic button: the user must choose Share and “Add to Home Screen”. Say so on the page, or it won’t happen.

{
  "name": "Shift plan – Example ApS",
  "short_name": "Shifts",
  "start_url": "/app/?source=pwa",
  "scope": "/app/",
  "display": "standalone",
  "background_color": "#ffffff",
  "theme_color": "#0b6e4f",
  "lang": "en",
  "icons": [
    { "src": "/icons/192.png", "sizes": "192x192", "type": "image/png" },
    { "src": "/icons/512.png", "sizes": "512x512", "type": "image/png" },
    { "src": "/icons/512-maskable.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
  ]
}

Save the file as /manifest.webmanifest and put <link rel="manifest" href="/manifest.webmanifest"> in the page’s <head>. scope keeps the app inside /app/, so links to the rest of the website open in the browser.

A service worker that doesn’t show stale pages

The most common mistake is a service worker that caches HTML and then shows an old version for weeks. Our rule of thumb: HTML always comes from the network, and the cache is used only when the network is gone. Static files such as CSS, JavaScript and icons may come from the cache. Change the version number when you release, and the old cache is cleared.

// /sw.js — HTML from the network (cache only offline), static files from cache, push
const VERSION = "v3";
const STATIC = ["/app/offline.html", "/app/app.css", "/app/app.js", "/icons/192.png"];

self.addEventListener("install", (event) => {
  event.waitUntil(caches.open(VERSION).then((c) => c.addAll(STATIC)));
  self.skipWaiting();
});

self.addEventListener("activate", (event) => {
  event.waitUntil(
    caches.keys().then((keys) =>
      Promise.all(keys.filter((k) => k !== VERSION).map((k) => caches.delete(k)))
    )
  );
  self.clients.claim();
});

self.addEventListener("fetch", (event) => {
  const req = event.request;
  if (req.method !== "GET") return;
  if (req.mode === "navigate") {
    event.respondWith(fetch(req).catch(() => caches.match("/app/offline.html")));
    return;
  }
  event.respondWith(
    caches.match(req).then((hit) => hit || fetch(req).then((res) => {
      if (res.ok && new URL(req.url).origin === location.origin) {
        const copy = res.clone();
        caches.open(VERSION).then((c) => c.put(req, copy));
      }
      return res;
    }))
  );
});

self.addEventListener("push", (event) => {
  const data = event.data ? event.data.json() : {};
  event.waitUntil(
    self.registration.showNotification(data.title || "New message", {
      body: data.body || "",
      icon: "/icons/192.png",
      data: { url: data.url || "/app/" }
    })
  );
});

self.addEventListener("notificationclick", (event) => {
  event.notification.close();
  event.waitUntil(self.clients.openWindow(event.notification.data.url));
});

Push on iPhone: only from the home screen, only after a tap

On iPhone and iPad web push has worked since version 16.4, but only for a web app added to the home screen. Permission may only be requested in response to something the user does, such as tapping a button. It builds on the standard Push API, Notifications API and service workers, and the icon can show a count with the Badging API. So we never ask when the page opens, only when the user taps “Notify me about new bookings”.

// /app/push.js — called from a button; VAPID_PUBLIC is the server's public key (base64url)
async function enablePush(VAPID_PUBLIC) {
  if (!("serviceWorker" in navigator) || !("PushManager" in window)) {
    alert("Add the app to your home screen first (Share → Add to Home Screen).");
    return;
  }
  // Ask first, while the tap still counts (Safari requires a user gesture)
  const answer = await Notification.requestPermission();
  if (answer !== "granted") return;
  const reg = await navigator.serviceWorker.ready;
  const key = Uint8Array.from(
    atob(VAPID_PUBLIC.replace(/-/g, "+").replace(/_/g, "/")), (c) => c.charCodeAt(0)
  );
  const sub = await reg.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: key });
  await fetch("/api/push/subscribe", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(sub)
  });
}

document.querySelector("#push-button").addEventListener("click", () => enablePush(window.VAPID_PUBLIC));

Register the service worker when the page loads: navigator.serviceWorker.register("/sw.js"). The button then uses serviceWorker.ready.

The server stores the subscription and sends with a VAPID key. In Python it takes a few lines with the pywebpush library:

import json
import os

from pywebpush import WebPushException, webpush


def send_push(subscription: dict, title: str, body: str, url: str = "/app/") -> bool:
    try:
        webpush(
            subscription_info=subscription,
            data=json.dumps({"title": title, "body": body, "url": url}),
            vapid_private_key=os.environ["VAPID_PRIVATE_KEY"],
            vapid_claims={"sub": "https://example.dk/contact"},
        )
        return True
    except WebPushException as exc:
        if exc.response is not None and exc.response.status_code in (404, 410):
            return False  # subscription expired: delete it from the database
        raise

If the push service answers 404 or 410, the user has removed the app or turned notifications off. Delete the subscription, or the list fills up with dead addresses.

Offline and the EU: what you can count on

Offline in practice means the app opens and shows a decent page or the last data it fetched when the network is gone. If users must work offline and send later, you need a queue in the app and a server that can receive the same request twice without creating duplicates.

In February 2024 Apple removed Home Screen web apps in the EU in the iOS 17.4 betas, citing the DMA, but reversed the decision on 1 March 2024. Apple’s current DMA page covers alternative app marketplaces and distribution from your own website, but says nothing about web apps. So test on a real iPhone before every release, and keep a fallback – e-mail or SMS – for messages that must not get lost.

A PWA is not always the answer. If the app needs caller ID, widgets or background GPS, it must be native; our own rule is Expo when a real app needs payments, push, the camera or location. And if your users live in Telegram, a Mini App can be easier; ours for the Ukrainian community reached about 300 users.

Sources

Last reviewed: 2026-12-03

Questions about PWAs

Why is there no install button on iPhone?

Safari does not show an automatic button. The user must choose Share and “Add to Home Screen”, so put a short guide on the page.

Why do users still see the old version?

Because the service worker caches HTML. Fetch HTML from the network, use the cache only offline, and change the cache name with every release.

Does web push cost anything?

Not for the messages themselves. The browser’s push service is free, and you only pay for your own server.

Can a PWA use the camera?

Yes, while the app is open, for example to scan a QR code. Camera and location in the background need a native app.

Fixed price, no commitment

Get a fixed price for your app or PWA

Tell us briefly what you use today and what you want to achieve. A person answers by e-mail with a proposal and a fixed price before any work starts.

  • A fixed price before we start
  • An answer by e-mail, no calls
  • Your details are used only to answer you

Fields marked with * are required.

What is it about?