AGENT SKILL

progressive-web-apps

Progressive Web Apps with service workers, manifest, and offline capabilities

License 许可
MIT
最近更新
2026-03-01
Stars
★ 3
Forks
2

01 前言 Front Matter

name
progressive-web-apps
license
MIT
metadata
{ "audience": "developers", "category": "web-development" }
description
Progressive Web Apps with service workers, manifest, and offline capabilities
compatibility
opencode

02 资源文件 1

03 SKILL.md 正文

What I do

  • Create PWAs with manifest.json
  • Implement service workers for offline support
  • Handle push notifications
  • Use cache strategies
  • Add to home screen capabilities
  • Implement background sync

When to use me

When building installable web apps with offline capabilities.

Manifest

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

Service Worker

// sw.js
self.addEventListener('install', event => {
  event.waitUntil(
    caches.open('v1').then(cache => {
      return cache.addAll(['/', '/index.html', '/styles.css']);
    })
  );
});

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

Cache Strategies

// Cache first
async function cacheFirst(request) {
  const cached = await caches.match(request);
  return cached || fetch(request);
}

// Network first
async function networkFirst(request) {
  try {
    return await fetch(request);
  } catch {
    return caches.match(request);
  }
}

// Stale-while-revalidate
async function staleWhileRevalidate(request) {
  const cached = await caches.match(request);
  const fetchPromise = fetch(request).then(response => {
    caches.open('v1').then(cache => cache.put(request, response));
    return response;
  });
  return cached || fetchPromise;
}

04 同仓库更多 Skills