A presentation about the Service Worker.
Talk about the difference between AppCache and ServiceWorker, also show as possible with him and the idea for the future.
Demo: https://github.com/brunoosilva/service-worker
5. APP CACHE
DISADVANTAGES
▸ Forget any url
▸ Set mime-type in server
▸ Nothing can give error 404 and 500
▸ No cache the manifest file (Danger)
▸ Impossible develop or debug
▸ etc …
8. SERVICE WORKER
WHATS IS ?
▸ Service workers essentially act as proxy servers that sit
between web applications, and the browser and network
(when available). They are intended to (amongst other
things) enable the creation of effective offline experiences,
intercepting network requests and taking appropriate
action based on whether the network is available and
updated assets reside on the server. They will also allow
access to push notifications and background sync APIs.
12. SERVICE WORKER
MAGICA.JS - UPDATE WITH INSTALL AND ACTIVATE
1 this.addEventListener('install', function(event) {
2 // Instala app, adicionar os arquivos no cache
3
4 event.waitUntil(
5 caches.open('bluesoft-v2').then(function(cache) {
6 return cache.addAll([
7 path,
8 path + 'index.html',
9 path + 'new-file.html'
10 ]);
11 })
12 );
13 });
14
15 this.addEventListener('activate', function(event) {
16 // App active and working
17
18 event.waitUntil(
19 caches.delete('bluesoft-v1')
20 );
21 });
13. SERVICE WORKER
ADVANTAGES
▸ Run in background ( with Browser closed )
▸ Based in promise
▸ Cache API
▸ Programmatic and controllable
▸ Chrome like ( Updates )
▸ The future
▸ etc …
14. SERVICE WORKER
DISADVANTAGES, BUT FOR SECURITY
▸ HTTPS only
▸ All asynchronous
▸ Not working localStorage (IndexDb only)
▸ Ajax synchronous
▸ Stop at any time
15. SERVICE WORKER
IDEAS FANTASTIC
BACKGROUND SYNC
1 registration.sync.register('event');
2 this.onsync = function(){}
PUSH NOTIFICATION
1 registration.pushRegistrationManager.register()
2 .then(function(details){ });
3
4 this.onpush = function(event){
5 new Notification(event.menssage.data);
6 };
7
8 this.onnotificationclick = function(){
9 new ServiceWorkerClient('/index.html')
10 };
GEOFENCING ALARM AND MUCH MORE…