Service worker in PWA

Service worker in PWA

by Valentyn Kubrak May 05, 2018
what_is_service_worker_in_PWA_

What is PWA

PWA stands for Progressive Web App. It was created by Google for describing its prospect of various application-like web experiences. This application contains many features of web pages including a control for connection, push notification, showing icons on home screen and many others.

Service Worker: who is it?

In turn, in PWA there is a service worker who plays a role of a proxy server which is situated between web applications, and between the browser and available network. In other words, service workers are web workers, namely JavaScript files which work separately from the main browser thread. Consequently, they don’t depend on the application which they are associated with. That’s why a service worker can receive different push messages from a server even when the application is not active at that moment.

Functions

The most significant functions of the service worker are:

  • providing people with the opportunity to have effective offline experience which a service worker creates;
  • catching network requests;
  • taking corresponding actions which depend on two factors: whether the network is available and whether updated assets reside on the server;
  • allowing users to have access in order to push notifications and background sync APIs;
  • controlling all network requests on a page.

Benefits

So, a service worker can provide developers with different activities for intercepting requests, caching and forging responses. Moreover, developers can have even offline access to certain pages (for example, while confirming an order or showing information about an e-ticket). They also can benefit from a cached version when loading some resources takes too much time. Furthermore, service workers are responsible for background communication with different servers. It means some additional features such as task scheduler, push notifications, background sync and so on and so forth.

Steps

There are some steps which you should do in order to benefit from a service worker. First of all, there is a registration. The user should register it in his or her main JavaScript code. Registration is compulsory because it shows the browser where the service worker is located. Then the second step is installing itself. And the final stage is activation.

Rate us
1 Star2 Stars3 Stars4 Stars5 Stars
(6 votes, average: 4.83 out of 5)
Loading...
Social Shares
Related Articles
AMP_vs_PWA PWA vs AMP comparison
Valentyn Kubrak
What_is_PWA What is PWA?
Alexandra Soloviova
PWA_example Examples of PWA
Alexandra Soloviova
what_is_service_worker_in_PWA_ Service worker in PWA
Valentyn Kubrak

Leave a Comment

Your email address will not be published. Required fields are marked *