Progressive Web Apps (PWA)

What lets a website act more like a native app: installable, working offline, and launchable from a home screen.

What is it?

A regular website needs a live connection and lives inside a browser tab. Some sites go further: you can "install" them like a native app, they keep working (at least partly) offline, and they get their own icon outside the browser. These are Progressive Web Apps, or PWAs. "Progressive" because they start as normal websites and add app-like features on top, with no separate app to build.

Two pieces make this work:

  • A manifest file is a small JSON file describing the site the way an app describes itself: name, icon, color scheme, and how it looks when launched (like hiding the address bar). It lets the browser offer to "install" the site and makes the icon behave like any other app icon.
  • A service worker is a script the browser can run in the background, separate from any tab, even when no tab for the site is open. It can intercept the page's network requests and decide how to respond, including serving a saved response instead of using the network. That's what lets a PWA keep working, at least partly, offline.

Explain like I'm 10

A manifest is a business card the site hands the operating system: 'here's my name, my icon, and how to launch me.' A service worker is a receptionist who keeps working even when the office (an open tab) is empty, with a filing cabinet of past documents to hand out instantly instead of always sending out for a fresh copy.

Examples

A basic web app manifest

{
  "name": "My Task App",
  "short_name": "Tasks",
  "start_url": "/",
  "display": "standalone",
  "icons": [
    { "src": "icon-192.png", "sizes": "192x192", "type": "image/png" }
  ]
}

Linked from the page's HTML, this JSON file tells the browser the site can be installed as an app, which icon to use, and to open without the usual address bar (display: standalone).

A service worker caching a response

self.addEventListener("fetch", (event) => {
  event.respondWith(
    caches.match(event.request).then((cached) => {
      return cached || fetch(event.request);
    })
  );
});

The service worker intercepts every request the page makes. If a matching response is in the cache, it's returned immediately, even offline; otherwise it falls back to a real network request.

How it works

When a page registers a service worker, the browser installs it to run in the background, independent of any tab, and keeps it registered across visits. From then on it can intercept the page's requests before they reach the network and decide whether to serve a cached response, fetch a fresh one, or mix both. That's what enables offline support.

The manifest is used separately, mainly at install time, to tell the operating system how to present the app once the user installs it.

Why does it exist?

PWAs close the gap between websites and native apps without building and maintaining a separate native app per platform. Offline support and installability used to be native-only. Service workers and manifests let an ordinary website opt into them with technology already in the browser.

When to use it

Consider a PWA when users would benefit from installing your site like an app, or when it must stay at least partly usable without a reliable connection. Good fits: note-taking apps, dashboards people check often, and tools used where connectivity is patchy.

When not to use it

A simple content site with no need for offline access or an app-like presence gains little from a service worker and manifest. Service workers also add real complexity around caching and updates: stale cached content can confuse users if it isn't managed carefully. Don't adopt them casually.

Common mistakes

  • Caching aggressively in a service worker with no plan for invalidating old data, leaving users stuck with stale content.

  • Assuming a manifest alone makes a site work offline. Offline support comes from the service worker, not the manifest.

  • Forgetting that a registered service worker stays installed and keeps intercepting requests on later visits, even after the tab is closed, which can surprise you during development.

Practice exercises

  1. Easy:

    Write a basic web app manifest for a sample site, with a name, icon, and display mode.

  2. Medium:

    Register a simple service worker on a test page and use DevTools to confirm it runs independently of the open tab.

  3. Hard:

    Extend a service worker to cache a page's core files on install and serve them when the network is unavailable. Test it by going offline in DevTools.

Interview questions

What are the two core pieces that make a website installable and offline-capable as a PWA?

A web app manifest, which describes the app's name, icon, and launch appearance, and a service worker, which can intercept network requests and serve cached responses without a connection.

What is a service worker, and how is it different from regular page JavaScript?

A script that runs in the background, independent of any open tab, and can intercept and respond to the page's network requests. Regular page scripts only run while their tab is open.

Does adding a manifest file alone make a site work offline?

No. The manifest only controls installability and how the installed app looks. Offline behavior comes from a service worker intercepting requests and serving cached responses.