JavaScript Async - Service Workers |
Written by Ian Elliot | |||||
Monday, 07 September 2020 | |||||
Page 4 of 4
Finally, how do you remove a Service Worker? The answer is that you first use the getRegistrations method to return a Promise which resolves to an array of ServiceWorkerRegistration objects: var regs=await navigator.serviceWorker. Next you scan though the array to find the Service Worker you want to remove, either by scope or by state say. You then use the unregister method of that ServiceWorkerRegistration object. For example to remove all Service Workers you would use: async function remove() { var regs = await navigator.serviceWorker. Browsers also provide ways to manage Service Workers. For example, Chrome has an Application tab which can be used to monitor and stop Service Workers. You can also select different behaviors which are useful in testing. For example you can simulate offline working:
The Future Of Service WorkersIn this chapter we have only touched on the basic use of Service Workers. In addition to acting as a proxy for resource requests, there are also interfaces for implementing periodic synchronization and push notifications. In short, Service Workers offer opportunities that are difficult to realize any other way. Many think that modern JavaScript, HTML and CSS plus new APIs such as Service Workers and those that are related will allow the web to develop in new ways and make web apps as good as desktop apps. At the time of writing it is estimated that over 94% of users have a browser that supports Service Workers. Many large companies have decided that this is enough to make it worth the trouble to implement Service workers – Google, Twitter, FaceBook, Bloomberg and You Tube. It does look as if Service Workers are the future of the web. Summary
Now Available as a Book:JavaScript AsyncYou can buy it from: Amazon Contents
Also by Ian ElliotJust JavaScript: An Idiomatic Approach To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info <ASIN:1871962560> <ASIN:1871962579> <ASIN:1871962528> <ASIN:1871962501> |
|||||
Last Updated ( Monday, 07 September 2020 ) |