An Overview of Service Worker

Posted By : Prachi Ahuja | 24-Apr-2019

Service Worker Support in Angular - 

Service workers are the scripts which usually run on the browser for managing the cache of an application. For the first time, service workers were introduced in Angular 5. Then in Angular 6 Service worker come up with better and new functionalities. So whenever we deploy our new application at that time we need to uninstall or deactivate the existing service worker. Angular 6 came up with the straightforward option to uninstall service worker, which was the new script file safety-worker.js which helps to deactivate the service worker.

 

 

The behaviour of Angular service worker -

Caching of an application means installing a new native application. The new application is treated as a single unit and stored as a cache.
With the help of caching user can see the latest version of an application every time when the page reloads. With service, worker bandwidth can also be conserved as it only downloads the resources when they are changed fully.

 

How to set up service worker functionality in browsers-
Firefox NightlyIn about go to config and set the value true for dom.serviceWorkers.enabled and then restart the browser.
 

Chrome Canary: Go to Google chrome://flags and then turn on experimental-web-platform-features and restart the browser.
 

Opera: Go to the opera://flags and then enable the Support feature for ServiceWorker and then restart the browser.

 

Points to be noted - 

1- Service worker cannot directly access the Dom.
2- Service worker makes the extensive use of promises.
3- Service worker gets terminated when not required and it automatically gets restarted when needed.

 

Need of HTTP - 

While the process of development you can easily use service worker through localhost but for the deployment of application, you must require proper set up of HTTPS. Service worker starts working after its proper activation as after proper activation it automatically starts listening to the functional events.

 

Conclusion - 

With the help of a service worker, users can access any web application without even having internet connection as after the activation of service worker full cache is used. That's why service worker is a most efficient feature of Angular which helps the user to access a web application any time.

About Author

Author Image
Prachi Ahuja

Prachi is a UI Developer having knowledge of HTML5, CSS3, Javascript, Jquery. She is dedicated towards her work.Her hobbies are drawings/paintings and writing articles.

Request for Proposal

Name is required

Comment is required

Sending message..