[Viktor Zozuliak] Service Worker - Native Apps Experience For The Web
Presentation from GDG DevFest Ukraine 2015 - the biggest Google related event in the country. October 23-24, Lviv. Learn more at http://devfest.gdg.org.ua/
place for SW API • SW is a separate file • SW can’t be registered from other domain • https is required, but localhost is white-listed • SW doesn’t have access to main app context • in real world we need to check if SW is supported: if ('serviceWorker' in navigator)
new API for network requests. It is based on Promise. Say “bye-bye” to callback based XHRs. • Fetch promise .catch() is executed when network is unavailable • Response - API for working with network responses • Response has stream nature so it can be read only once. . clone()method is used to overcome this.
every service worker file update • Service Worker file is considered updated when it changes in size • Activate event can be used to clean up the old version stuff • Service Worker has two update modes - cold (default) and hot
step • set service worker to waiting state • release old worker when all the pages with current active worker are closed • run activate step when page with app is opened • take control over the page • ==> it’s like Google Chrome update model!
• new worker version is not compatible with old app • new app version is not compatible with old one (guarantees that different versions don’t run in different tabs)
features) Firefox - quite good (key features, many features in nightly) Opera - good (key features) IE - optimistic (no support, but under consideration) Safari - bad (no public commitment) Details:
Is Service Worker Ready? by Jake Archibald: https://jakearchibald.github.io/isserviceworkerready/ • Introduction To Service Worker on HTML5 Rocks : http://www.html5rocks.com/en/tutorials/service-worker/introduction/ • Service Worker Libraries maintained by Google: https://developers.google.com/web/tools/service-worker-libraries/