home / skills / secondsky / claude-skills / progressive-web-app

This skill helps you build installable PWAs with offline support, service workers, and install prompts to enhance reliability and engagement.

npx playbooks add skill secondsky/claude-skills --skill progressive-web-app

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.4 KB
---
name: progressive-web-app
description: Progressive Web Apps with service workers, web manifest, offline support, installation prompts. Use for installable web apps, offline functionality, push notifications, or encountering service worker registration, cache strategy, manifest configuration errors.
license: MIT
---

# Progressive Web App (PWA)

Build web applications that work like native apps with offline support and installability.

## Web App Manifest

```json
{
  "name": "My Application",
  "short_name": "MyApp",
  "start_url": "/",
  "display": "standalone",
  "background_color": "#ffffff",
  "theme_color": "#000000",
  "icons": [
    { "src": "/icon-192.png", "sizes": "192x192", "type": "image/png" },
    { "src": "/icon-512.png", "sizes": "512x512", "type": "image/png" }
  ]
}
```

## Service Worker

```javascript
const CACHE_NAME = 'app-v1';
const STATIC_ASSETS = ['/', '/index.html', '/styles.css', '/app.js'];

// Install
self.addEventListener('install', event => {
  event.waitUntil(
    caches.open(CACHE_NAME).then(cache => cache.addAll(STATIC_ASSETS))
  );
});

// Fetch with cache-first strategy
self.addEventListener('fetch', event => {
  event.respondWith(
    caches.match(event.request).then(cached => {
      if (cached) return cached;

      return fetch(event.request).then(response => {
        if (response.status === 200) {
          const clone = response.clone();
          caches.open(CACHE_NAME).then(cache => cache.put(event.request, clone));
        }
        return response;
      });
    })
  );
});
```

## Install Prompt

```javascript
let deferredPrompt;

window.addEventListener('beforeinstallprompt', e => {
  e.preventDefault();
  deferredPrompt = e;
  showInstallButton();
});

async function installApp() {
  if (!deferredPrompt) return;
  deferredPrompt.prompt();
  const { outcome } = await deferredPrompt.userChoice;
  console.log('Install outcome:', outcome);
  deferredPrompt = null;
}
```

## Push Notifications

```javascript
async function subscribeToPush() {
  const registration = await navigator.serviceWorker.ready;
  const subscription = await registration.pushManager.subscribe({
    userVisibleOnly: true,
    applicationServerKey: VAPID_PUBLIC_KEY
  });
  await sendSubscriptionToServer(subscription);
}
```

## PWA Checklist

- [ ] HTTPS enabled
- [ ] Web manifest configured
- [ ] Service worker registered
- [ ] Offline fallback page
- [ ] Responsive design
- [ ] Fast loading (<3s on 3G)
- [ ] Installable

Overview

This skill helps you implement production-ready Progressive Web Apps (PWAs) with service workers, a web app manifest, offline support, and installability. It provides concrete patterns for cache strategies, beforeinstallprompt handling, and push notification subscription in TypeScript-ready projects. Use it to add native-like behavior and reliability to React + Cloudflare deployments.

How this skill works

The skill supplies a manifest template and a service worker pattern that implements a cache-first fetch strategy with runtime caching for new resources. It includes code snippets for capturing the beforeinstallprompt event and triggering the install flow, and for subscribing users to push notifications via the Push API and VAPID keys. It also outlines a PWA checklist to verify HTTPS, offline fallbacks, performance targets, and installability.

When to use it

  • You want installable web apps that behave like native apps on mobile and desktop.
  • You need offline support and predictable caching for flaky or slow networks.
  • You are configuring service worker registration or debugging cache-related issues.
  • You want to add push notifications and manage push subscriptions securely.
  • You must meet a PWA checklist for Lighthouse or app-store-like quality gates.

Best practices

  • Serve the site over HTTPS and host the manifest at the app root for correct scope.
  • Use a stable cache name and migrate caches on service worker activate to avoid stale data.
  • Keep an offline fallback page and handle navigation requests explicitly for SPA routing.
  • Limit cached dynamic responses and validate response.status before caching clones.
  • Defer the install prompt UI until the app is ready and respect userChoice outcome.

Example use cases

  • Make a React + Cloudflare Pages site installable with a manifest and service worker.
  • Add offline-first behavior to an internal dashboard so it remains usable during network loss.
  • Implement push notifications for user activity updates using VAPID keys and server-side subscription storage.
  • Debug caching errors by inspecting service worker registration and active cache contents.
  • Meet performance and Lighthouse PWA criteria for app distribution or enterprise QA.

FAQ

How do I update cached assets without breaking users?

Use a cache version name and update it in the new service worker, then in activate clear old caches and claim clients. This lets clients switch to the new cache on reload.

Where should the manifest and service worker be hosted?

Place the manifest at the app root (or adjust scope) and register the service worker from a root-level script so it controls the appropriate URL scope.