不注册可控制页面和“start_url”的服务工作进程

Published on Updated on

Translated to: English, Español, Português, 한국어, Pусский, 日本語

注册服务工作进程是启用以下关键渐进式 Web 应用程序 (PWA) 特性的第一步:

  • 离线工作
  • 支持推送通知
  • 可以安装到设备

有关更多信息,请参阅文章服务工作进程和缓存存储 API

浏览器兼容性

除 Internet Explorer 外的所有主流浏览器都支持服务工作进程。请参阅浏览器兼容性

Lighthouse 服务工作进程审计如何失败

Lighthouse 会标记不注册服务工作进程的页面:

Lighthouse 审计显示网站不注册服务工作进程

Lighthouse 检查 Chrome 远程调试协议是否返回一个服务工作进程版本。如果不返回,则审计失败。

In the Lighthouse report UI the full PWA badge is given when you pass all of the audits in all of the PWA subcategories (Fast and reliable, Installable, and PWA optimized).

如何注册服务工作进程

Success

Workbox is the recommended approach for adding service workers to websites because it automates a lot of boilerplate, makes it easier to follow best practices, and prevents subtle bugs that are common when using the low-level ServiceWorker API directly.

注册服务工作进程只需几行代码,但使用服务工作进程的唯一原因是可以实现上述 PWA 特性之一。实际上,实现这些特性需要更多工作:

资源

Updated on 改进文章

This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.