mcpField
P
progressive-web-app

progressive-web-app

github.com/secondsky開発240512 回インストール5 週間前に更新
リポジトリ

progressive-web-app について

オフライン対応とインストール機能を備えたプログレッシブウェブアプリの開発者向けスキルです。マニフェスト、Service Worker、インストールプロンプト、プッシュ通知の例を扱います。

主な機能

  1. 01Web App Manifestの設定例
  2. 02Service Workerによるアセットキャッシュ
  3. 03インストールプロンプトの処理
  4. 04プッシュ通知の購読例
  5. 05PWA公開チェックリスト

活用シーン

  1. 01Webアプリへのオフラインアセットキャッシュ追加
  2. 02アプリのインストールフロー設定
  3. 03プッシュ通知の購読実装
  4. 04PWA公開要件の確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/secondsky/claude-skills --skill progressive-web-app

インストール後、Claude Code で/progressive-web-appを入力して読み込まれたか確認します。

詳細

プログレッシブウェブアプリ(PWA)

オフライン対応とインストール機能を備え、ネイティブアプリのように動作するウェブアプリケーションを構築します。

ウェブアプリマニフェスト

{
  "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" }
  ]
}

サービスワーカー

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;
      });
    })
  );
});

インストールプロンプト

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;
}

プッシュ通知

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 チェックリスト

  • HTTPS が有効
  • ウェブマニフェストを設定済み
  • サービスワーカーを登録済み
  • オフライン時のフォールバックページ
  • レスポンシブデザイン
  • 高速な読み込み(3G で 3 秒未満)
  • インストール可能

コメント