javascript – 服务工作者可以做什么,网络工作者不能?
作者:互联网
服务工作者可以做什么,网络工作者不能?或相反亦然?
Web工作者似乎是服务工作者功能的一个子集.这个对吗?
解决方法:
他们的目标有很大不同:
网络工作者
Web Workers provide a simple means for web content to run scripts in background threads. The worker thread can perform tasks without
interfering with the user interface. In addition, they can perform I/O
using XMLHttpRequest (although the responseXML and channel attributes
are always null). Once created, a worker can send messages to the
JavaScript code that created it by posting messages to an event
handler specified by that code (and vice versa.)
服务人员
Service workers essentially act as proxy servers that sit between web
applications, and the browser and network (when available). They are
intended to (amongst other things) enable the creation of effective
offline experiences, intercepting network requests and taking
appropriate action based on whether the network is available and
updated assets reside on the server. They will also allow access to
push notifications and background sync APIs.
因此,Web Workers可以方便地运行昂贵的脚本,而不会导致用户界面冻结,
而Service Worker可用于修改网络请求的响应(例如,构建脱机应用程序时).
标签:html,javascript,web-worker,service-worker,w3c 来源: https://codeday.me/bug/20190928/1826582.html