Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  139] [ 5]  / answers: 1 / hits: 57784  / 7 Years ago, sat, december 23, 2017, 12:00:00

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();

More From » reactjs

 Answers
4

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 creates a service worker for you without your configuration by default. To learn more;




[#55602] Wednesday, December 20, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dallasb

Total Points: 657
Total Questions: 98
Total Answers: 97

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;