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

service-worker

它能做什么

这个技能检查网站是否注册了 Service Worker,并在需要时为静态文件添加缓存和离线备用页面。它面向希望重复访问更快、移动端性能更好的开发者。

适用场景

  • ✓你请智能体为网站添加缓存或离线支持的时候。
  • ✓重复访问很慢,因为静态文件每次都要重新下载的时候。
  • ✓你在准备渐进式 Web 应用,需要一个可正常工作的 Service Worker 的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/service-worker/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请帮我为网站添加 Service Worker,让重复访问加载更快,并且在网络不好时仍能使用吗?”

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

工作原理

智能体会在主脚本中注册 Service Worker,在安装时预缓存关键静态文件,并为每种资源选择缓存方式。它还会添加 activate 步骤,在网站更新时删除旧缓存。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Register a service worker for caching and offline support

Service workers act as a programmable network proxy between the browser and the network. They eliminate repeated server round-trips for static assets, cut load times on repeat visits by 50–90 %, and allow the app to function at all on flaky or offline networks — which is critical for users on mobile or low-bandwidth connections.

Quick Reference

  • Register a service worker in your main JavaScript entry point
  • Use an install event to pre-cache critical static assets
  • Choose a caching strategy (cache-first, network-first, stale-while-revalidate) per resource type
  • Implement an activate event to clean up old caches on update

Check

Check whether a service worker is registered and whether it caches static assets, API responses, or provides an offline fallback.

Fix

Add a service worker registration call and implement appropriate caching strategies for static assets and navigation requests.

Explain

Explain how service workers intercept network requests and how different caching strategies trade off freshness vs. speed.

Code Review

Review the service worker file and its registration. Flag missing install/ activate lifecycle handlers, absent cache-versioning, missing fetch handlers, and any patterns that could cause stale content to be served indefinitely.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/performance/service-worker

常见问题

主要的缓存策略有哪些?

这个技能列出了 cache-first、network-first 和 stale-while-revalidate,并建议为每种资源类型选择一种。

为什么要清理旧缓存?

activate 步骤会删除过时的缓存文件,这样更新后访客就不会一直看到旧版本。

过期内容会造成问题吗?

会。这个技能提醒,某些缓存方式可能会无限期地提供过期内容,因此智能体会仔细检查它们。

详情

作者的原始描述

Use when auditing repeat-visit performance, adding offline support, or evaluating PWA readiness for a web application.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#3016
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能