Service Worker 和 iOS / Safari
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29895387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Service workers and iOS / Safari
提问by Karol Klepacki
On Chromium's page about service workers there's noted that
在 Chromium 的关于 service workers 的页面上指出
Service Workers are not supported by Chrome on iOS.
iOS 上的 Chrome 不支持 Service Worker。
I assume that it can be delivered to iOS using some cordova plugins. Is there any other way to use Service Workers on iOS devices?
I'm worried about time between shipping new version on iOS and new version of cordova.
我假设它可以使用一些cordova插件交付给iOS。有没有其他方法可以在 iOS 设备上使用 Service Workers?
我担心在 iOS 上发布新版本和 Cordova 新版本之间的时间。
Does anyone know if Chrome on iOS is going to support service workers in the future? :)
有谁知道 iOS 上的 Chrome 将来是否会支持 Service Worker?:)
采纳答案by Karol Klepacki
Although Ian's answer was great by the time it was posted (04.2015), this question became important point of entry for a lot people interested in service workers and Progressive Web Apps and answer is much broader now.
尽管 Ian 的回答在发布时 (04.2015) 已经很好了,但对于许多对 Service Worker 和 Progressive Web Apps 感兴趣的人来说,这个问题成为了重要的切入点,而且现在的答案要广泛得多。
Feedback from Apple
来自苹果的反馈
30.03.2018: Service workers are shipped with Safari 11.1. Good job! https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_11_1.html
30.03.2018:Service Worker 随 Safari 11.1 一起提供。做得好!https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_11_1.html
20.12.2017: Service workers enabled by default in Safari Technology Preview 46 https://webkit.org/blog/8042/release-notes-for-safari-technology-preview-46/
20.12.2017:Safari Technology Preview 46 https://webkit.org/blog/8042/release-notes-for-safari-technology-preview-46/
04.08.2017: Work officially in progress :) https://webkit.org/status/#specification-service-workers
04.08.2017: 工作正式进行:) https://webkit.org/status/#specification-service-workers
07.2017: More positive signals on webkit-dev:
07.2017:关于webkit-dev 的更多积极信号:
Apple engineers from the WebKit team have been heavily involved in ServiceWorkers spec discussions over the past few years. Many of our concerns with the spec have been addressed, especially for Fetch service workers which generally don't run beyond the scope of pages that use them. While we have not done any implementation work, the "under consideration" in this case is meant literally. We actually are considering it.
在过去几年中,来自 WebKit 团队的 Apple 工程师一直积极参与 ServiceWorkers 规范的讨论。我们对规范的许多担忧已经得到解决,特别是对于 Fetch Service Worker,它们通常不会超出使用它们的页面的范围。虽然我们没有做任何实施工作,但在这种情况下,“考虑中”是字面意思。我们实际上正在考虑它。
06.2016: According to Jake Archibald's 'Is ServiceWorker ready?'current status of iOS (Safari) is:
06.2016:根据Jake Archibald 的“ServiceWorker 准备好了吗?” iOS(Safari)的当前状态是:
Under consideration, Brief positive signals in five year plan.
Please be aware, that it affects all browsers on iOS - due to Apple's limitations, Chrome on iOS is using WKWebView - the same rendering engine as Safari, and it's only a tiny wrapper around it, so it's limited to current functionalities.
请注意,它会影响 iOS 上的所有浏览器——由于 Apple 的限制,iOS 上的 Chrome 使用 WKWebView——与 Safari 相同的渲染引擎,它只是它的一个很小的包装器,所以它仅限于当前的功能。
Resources
资源
The most recognized place of tracking current status of service worker is Jake Archibald's 'Is ServiceWorker ready?'.
最受认可的跟踪 Service Worker 当前状态的地方是Jake Archibald 的“ServiceWorker 准备好了吗?” .
There's another resource that gathers these information, providing more information on various Chromium builds, most popular in China and covering some more details: https://ispwaready.toxicjohann.com/
还有另一个资源可以收集这些信息,提供有关在china最流行的各种 Chromium 版本的更多信息,并涵盖更多详细信息:https: //ispwaready.toxicjohann.com/
Controversies
争议
Wide-scale debate about Apple participation in modern web features has been triggered after Nolan Lawson's article Safari is the new IE (06/2015)whose main point was that
在 Nolan Lawson 的文章Safari is the new IE (06/2015)之后,引发了关于 Apple 参与现代 Web 功能的大规模辩论,其主要观点是
In recent years, Apple's strategy towards the web can most charitably be described as “benevolent neglect.”
近年来,苹果对网络的战略可以用“仁慈的忽视”来形容。
The main argument of the opposing party was that service worker and the rest of offline/PWA features are not customer-centric - the focus of Safari development.
对方的主要论点是 Service Worker 和其他离线/PWA 功能不是以客户为中心的——Safari 开发的重点。
Some people are even more radical like Greg Blass in his article (07/2017)who states that
有些人甚至更激进,比如Greg Blass 在他的文章 (07/2017)中指出
Apple treats web apps like second class citizens because they don't generate money like native apps in the app store.
Apple 将 Web 应用程序视为二等公民,因为它们不像应用程序商店中的本地应用程序那样赚钱。
Common point is that Apple is falling behind other vendors (Chrome, Firefox, Edge) with developing features that'll improve web experience, but also has very slow pace of fixing critical bugs that makes some features technically unusable.
共同点是,Apple 在开发可改善 Web 体验的功能方面落后于其他供应商(Chrome、Firefox、Edge),但在修复导致某些功能在技术上无法使用的关键错误方面的速度也非常缓慢。
回答by Ian Clelland
I don't know if or when Chrome on iOS will support Service Worker, but it is definitely possible today with Cordova.
我不知道 iOS 上的 Chrome 是否或何时支持 Service Worker,但今天使用 Cordova 绝对有可能。
The Service Worker pluginon npm will let you use the API in Cordova apps on iOS.
npm 上的Service Worker 插件可让您在 iOS 上的 Cordova 应用程序中使用 API。
回答by Greg Blass
I wrote an article calling out Apple on the topic:
我写了一篇关于这个主题的文章,呼吁苹果:
It got retweeted by a couple key people, then posted on hacker news, and continued to get some good twitter activity. A week later, they started development on it. So - stay tuned, it's coming!
它被几个关键人物转发,然后发布在黑客新闻上,并继续在推特上获得一些不错的活动。一周后,他们开始开发它。所以 - 敬请期待,它来了!
回答by Johnny Oshika
Service worker is available in Safari 11.1, which shipped March 29, 2018 with iOS 11.3 and macOS 10.13.4:
Service Worker 在 Safari 11.1 中可用,该版本于 2018 年 3 月 29 日随 iOS 11.3 和 macOS 10.13.4 一起发布:
Note:
笔记:
- Service Worker + Cache API are both supported (Cache API is actually a pre-requisite for Service Worker support)
- Some noteworthy problems with Apple's implementation of Service Worker: https://medium.com/@firt/pwas-are-coming-to-ios-11-3-cupertino-we-have-a-problem-2ff49fd7d6ea
- No "Add to Home Screen" prompt
- No Push API
- No Background Sync
- Service Worker + Cache API 都支持(Cache API 实际上是 Service Worker 支持的先决条件)
- Apple 实施 Service Worker 的一些值得注意的问题:https: //medium.com/@firt/pwas-are-coming-to-ios-11-3-cupertino-we-have-a-problem-2ff49fd7d6ea
- 没有“添加到主屏幕”提示
- 无推送 API
- 无后台同步
回答by zaffar
Answer to the @mclIf you change your code in the service worker:
对@mcl 的回答如果您更改了 service worker 中的代码:
self.addEventListener( 'install', function(){
return self.skipWaiting( );
});
to the following code, it should work. I have changed all the variables as well so just copy paste it.
对于以下代码,它应该可以工作。我也更改了所有变量,因此只需复制粘贴即可。
self.addEventListener('install', event => {
console.log('Attempting to install service worker and cache static assets');
event.waitUntil(
caches.open(FILES_CACHE)
.then(cache => {
return cache.addAll(urlsToCache);
})
);
});
回答by aWebDeveloper
Finally, Apple has added support for service worker in their TP. You can read more about safari's PWA support here
最后,Apple 在他们的 TP 中添加了对 service worker 的支持。您可以在此处阅读有关 safari 的 PWA 支持的更多信息
Here is the service worker detailed support info http://ispwaready.toxicjohann.com/
这是 Service Worker 的详细支持信息 http://ispwaready.toxicjohann.com/