registerServiceWorker在React JS中做什么? [英] What does registerServiceWorker do in React JS?
问题描述
我是React的新手,我想知道下面的代码中registerServiceWorker()的目的是什么?
I'm a newbie in React and I was wondering what is the purpose of registerServiceWorker() in the following code?
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
推荐答案
服务工作者是一个Web API,可帮助您缓存资产和其他文件,以便当用户处于脱机状态或网络速度较慢时,他/她仍然可以在屏幕上查看结果,因此,它可以帮助您建立更好的用户体验,这就是您现在应该了解的关于服务人员的知识.都是要向您的站点添加脱机功能.
The service worker is a web API that helps you cache your assets and other files so that when the user is offline or on slow network, he/she can still see results on the screen, as such, it helps you build a better user experience, that's what you should know about service worker's for now. It's all about adding offline capabilities to your site.
React在默认情况下无需您的配置即可为您创建服务工作者.了解更多;
React creates a service worker for you without your configuration by default. To learn more;
这篇关于registerServiceWorker在React JS中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!