什么是react js中的service worker [英] What is service worker in react js

查看:57
本文介绍了什么是react js中的service worker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建 React 应用程序时,默认调用 Service Worker.为什么使用 Service Worker?默认调用的原因是什么?

When creating a react app, service worker is invoked by default. Why service worker is used? What is the reason for default invoking?

推荐答案

您的应用程序可能不需要 Service Worker.如果您使用 create-react-app 创建项目,则默认调用它

You may not need a service worker for your application. If you are creating a project with create-react-app it is invoked by default

Service Worker 在this 文章.总结一下

Service workers are well explained in this article. To Summarise from it

service worker 是浏览器在背景,与网页分开,打开功能之门不需要网页或用户交互.今天,他们已经包括推送通知后台同步等功能,并具有拦截和处理网络请求的能力,包括以编程方式管理响应缓存.

A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction. Today, they already include features like push notifications and background sync and have ability to intercept and handle network requests, including programmatically managing a cache of responses.

在未来,Service Worker 可能会支持其他的东西,比如定期同步地理围栏.

In the future, service workers might support other things like periodic sync or geofencing.

根据这个PR to create-react-app

According to this PR to create-react-app

Service workers 通过 create-react-app 引入SWPrecacheWebpackPlugin.

Service workers are introduced with create-react-app via SWPrecacheWebpackPlugin.

使用具有缓存优先策略的服务器工作者可提供性能优势,因为网络不再是实现的瓶颈导航请求.然而,这确实意味着开发人员(和用户)只会在N+1"上看到已部署的更新访问页面,因为先前缓存的资源在背景.

Using a server worker with a cache-first strategy offers performance advantages, since the network is no longer a bottleneck for fulfilling navigation requests. It does mean, however, that developers (and users) will only see deployed updates on the "N+1" visit to a page, since previously cached resources are updated in the background.

在新应用中默认启用对 register service worker 的调用,但您可以随时将其删除,然后您就会恢复正常行为.

The call to register service worker is enabled by default in new apps but you can always remove it and then you’re back to regular behaviour.

这篇关于什么是react js中的service worker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆