跳到正文
Skillpedia
网站与界面(前端)48k · #5515

progressive-web-app

它能做什么

PWA 是一种看起来和用起来都像应用的网站,可以安装到手机上,还能离线使用。它借助现代技术,速度快,也更可靠。

适用场景

  • ✓当你希望你的网站可以离线工作时。
  • ✓当你希望网站能够安装到设备的主屏幕上时。
  • ✓当你希望提升网站的速度和可靠性时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/progressive-web-app/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/progressive-web-app/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我怎样才能让我的网站离线可用,并且能像应用一样安装?”

每周 5 个新技能,1 分钟读完。

工作原理

它的原理是使用一个描述应用信息的“manifest”文件,以及一段在后台运行的额外代码,也就是“service worker”(服务工作线程)。这段代码负责管理缓存(即保存下来的文件),让网站在没有网络连接时也能正常使用。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Progressive Web Apps (PWAs)

Overview

A Progressive Web App is a web application that uses modern browser capabilities to deliver a fast, reliable, and installable experience — even on unreliable networks. The three required pillars are:

  1. HTTPS — Required in production for service workers to register (localhost is exempt for development).
  2. Web App Manifest (manifest.json) — Makes the app installable and defines its appearance on device home screens.
  3. Service Worker (sw.js) — A background script that intercepts network requests, manages caches, and enables offline functionality.

When to Use This Skill

  • Use when the user wants their web app to work offline or on unreliable networks.
  • Use when building a mobile-first web project where users should be able to install the app to their home screen.
  • Use when the user asks about caching strategies, service workers, or improving web app performance and resilience.
  • Use when the user mentions Workbox, web app manifests, background sync, or push notifications for the web.
  • Use when the user asks "can my website be installed like an app?" or "how do I make my site work offline?" — even if they don't use the word PWA.

Deliverables Checklist

Every PWA implementation must include these files at minimum:

  • index.html — Links manifest, registers service worker
  • manifest.json — Full app metadata and icon set
  • sw.js — Service worker with install, activate, and fetch handlers
  • app.js — Main app logic with SW registration and install prompt handling
  • offline.html — Fallback page shown when navigation fails offline (required — missing file will cause install to fail)

Step 1: Web App Manifest (manifest.json)

Defines how the app appears when installed. Must be linked from <head> via <link rel="manifest">.

{
  "name": "My Awesome PWA",
  "short_name": "MyPWA",
  "description": "A fast, offline-capable Progressive Web App.",
  "start_url": "/",
  "scope": "/",
  "display": "standalone",
  "orientation": "portrait-primary",
  "background_color": "#ffffff",
  "theme_color": "#0055ff",
  "icons": [
    {
      "src": "/assets/icons/icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png",
      "purpose": "any maskable"
    },
    {
      "src": "/assets/icons/icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png",
      "purpose": "any maskable"
    }
  ],
  "screenshots": [
    {
      "src": "/assets/screenshots/desktop.png",
      "sizes": "1280x720",
      "type": "image/png",
      "form_factor": "wide"
    }
  ]
}

Key fields:

  • display: standalone hides browser UI; minimal-ui shows minimal controls; browser is standard tab.
  • purpose: "maskable" on icons enables adaptive icons on Android (safe zone matters — keep content in center 80%).
  • screenshots is optional but required for Chrome's enhanced install dialog on desktop.

Step 2: HTML Shell (index.html)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Awesome PWA</title>

  <!-- PWA manifest -->
  <link rel="manifest" href="/manifest.json">

  <!-- Theme color for browser chrome -->
  <meta name="theme-color" content="#0055ff">

  <!-- iOS-specific (Safari doesn't fully use manifest) -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="default">
  <meta name="apple-mobile-web-app-title" content="MyPWA">
  <link rel="apple-touch-icon" href="/assets/icons/icon-192x192.png">

  <link rel="stylesheet" href="/styles.css">
</head>
<body>
  <div id="app">
    <header><h1>My PWA</h1></header>
    <main id="content">Loading...</main>
    <!-- Optional: install button, hidden by default -->
    <button id="install-btn" hidden>Install App</button>
  </div>
  <script src="/app.js"></script>
</body>
</html>

Step 3: Service Worker Registration & Install Prompt (app.js)

// ─── Service Worker Registration ───────────────────────────────────────────
if ('serviceWorker' in navigator) {
  window.addEventListener('load', async () => {
    try {
      const registration = await navigator.serviceWorker.register('/sw.js');
      console.log('[App] SW registered, scope:', registration.scope);
    } catch (err) {
      console.error('[App] SW registration failed:', err);
    }
  });
}


…
常见问题

什么是“service worker”?

它是一段在浏览器后台运行的脚本(代码)。它可以拦截网络请求、管理文件缓存,并让你的网站支持离线使用。

什么是“Web App Manifest”?

它是一个 JSON 文件,里面记录了你的网页应用的信息,比如名称、图标、颜色,以及安装后的显示方式。有了它,网站才能被添加到设备的主屏幕上。

我需要 HTTPS 吗?

需要。正式发布的网站上,service worker 必须运行在 HTTPS 下。本地开发环境(localhost)是例外。

详情

作者的原始描述

Build Progressive Web Apps (PWAs) with offline support, installability, and caching strategies. Trigger whenever the user mentions PWA, service workers, web app manifests, Workbox, 'add to home screen', or wants their web app to work offline, feel native, or be installable.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5515
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能