Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does registerServiceWorker do in React JS?

People also ask

How do you use web workers in React?

The first thing to do is to create the web worker using the Worker constructor. Then inside our button's event listener, we send a number to the worker using worker. postMessage({ num }) . After that, we set a function to listen for errors in the worker.

What is a web service worker?

A Service Worker is a script that executes in the background, in a separate thread from the browser UI. Service worker cache makes it possible for a web site to function offline. They are the technical powerhouse that levels up a website to a progressive web app.

What is reportWebVitals in React?

Create React App includes a built-in tool for measuring the real life performance of your app. It is called reportWebVitals and it measures a set of metrics that aim to capture the user experience of a web page. This set is called web vitals and includes: First Contentful Paint. Largest Contentful Paint.


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;

  • Service Workers, MDN
  • Service Workers, Google Web Fundamentals
  • Simple offline site using service worker, CSS Tricks
  • Server worker: A case study, Smashing Magazine