What is service worker in react js

后端 未结 3 1409
無奈伤痛
無奈伤痛 2021-01-30 08:15

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

3条回答
  •  难免孤独
    2021-01-30 08:30

    I'd like to add 2 important considerations about Service Workers to take into account:

    1. Service Workers require HTTPS. But to enable local testing, this restriction doesn't apply to localhost. This is for security reasons as a Service Worker acts like a man in the middle between the web application and the server.

    2. With Create React App Service Worker is only enabled in the production environment, for example when running npm run build.

    Service Worker is here to help developing a Progressive Web App. A good resource about it in the context of Create React App can be found in their website here.

提交回复
热议问题