SlideShare uma empresa Scribd logo
1 de 34
Turin Web Performance Group
Service Workers
Forza lavoro al servizio della tua Performance
con Piero Bellomo, @ptbello
performance-obsessed full stack dev
● Contesto
● Le PWA
● I Service Worker
● Service Worker Performance
● Fonti e approfondimenti
Indice
PWA
“Progressive Web Applications (PWAs) are web
applications that load like regular web pages or
websites but can offer functionality traditionally
available only to native apps.
PWAs combine the open standards of the web
to provide benefits of a rich mobile experience.”
Wikipedia
The Future
Native Apps
Progressive Web Apps
Contesto ➜ Le PWA
Native feel
● Add to Home screen
● Hardware access
● Notifiche push
● ...and the list goes on
Contesto ➜ Le PWA
PWA
Native feel
● Add to Home screen
● Hardware access
● Notifiche push
● ...and the list goes on
Reliability
Modalità offline in
funzione della
connettività disponibile
Contesto ➜ Le PWA
PWA
Native feel
● Add to Home screen
● Hardware access
● Notifiche push
● ...and the list goes on
Reliability
Modalità offline in
funzione della
connettività disponibile
Performance
Ooooh!
Caching!
Contesto ➜ Le PWA
PWA
Gli ingredienti di una PWA
● https://
● Manifest
Contesto ➜ Le PWA ➜ Ingredienti
● APIs
● SW
Manifest
Contesto ➜ Le PWA ➜ Ingredienti ➜ Manifest
…of the Communist Party?
Ahem, sorry, No Party.
Manifest
Un file Json con informazioni utili al (mobile) OS
per presentare l’App nelle diverse situazioni
Contesto ➜ Le PWA ➜ Ingredienti ➜ Manifest
<head>
...
<link rel="manifest" href="myapp.webmanifest">
...
</head>
APIs
Il Presente
● Audio/Video
● Background Sync
● Storage
○ LocalStorage (obsoleto)
○ IndexedDB
○ Cache API
● Fetch (XMLHttpRequest on crack)
● Geolocation
● Notifiche
Il Futuro
● Payment Request
● Web Speech
● Web Authentication
● Web Share
● Geofencing?
● Gamepad?
Contesto ➜ Le PWA ➜ Ingredienti ➜ APIs
Service Worker
Contesto ➜ Le PWA ➜ Ingredienti ➜ Service Worker
Il Cervello della banda
Cos’è un Service Worker
● Background Process
può essere idle o active
Contesto ➜ il Service Worker ➜ Cos’è
Cos’è un Service Worker
● Background Process
può essere idle o active
● Network Proxy
intercetta richieste con fetch
Contesto ➜ il Service Worker ➜ Cos’è
Cos’è un Service Worker
● Background Process
può essere idle o active
● Network Proxy
intercetta richieste con fetch
● No DOM access
ma accesso indiretto via postMessage e Clients
Contesto ➜ il Service Worker ➜ Cos’è
Cos’è un Service Worker
● Background Process
può essere idle o active
● Network Proxy
intercetta richieste con fetch
● No DOM access
ma accesso indiretto via postMessage e Clients
● Persistent Data Access
client-side storage con Cache
Contesto ➜ il Service Worker ➜ Cos’è
Registrazione
index.html
<head>
...
<script src="./app.js"></script>
...
</head>
if( 'serviceWorker' in navigator ) {
navigator.serviceWorker.register('./sw.js');
} else {
console.log('serviceWorker not available!);
}
add Event Listeners ➜
app.js
sw.js
Contesto ➜ il Service Worker ➜ Registrazione
self.addEventListener('install', function(e) {
//… do stuff that happens only once
// (will also fire if sw is updated)
// e.g. cache static assets
}
Lifecycle
Contesto ➜ il Service Worker ➜ Lifecycle
self.addEventListener('activate', function(e) {
//… do stuff that only need to happen
// when you updated to a newer version
// e.g. clear/amend cache
}
Lifecycle
Contesto ➜ il Service Worker ➜ Lifecycle
Lifecycle
Contesto ➜ il Service Worker ➜ Lifecycle
self.addEventListener('fetch', function (e) {
// intercept and manipulate every. single. request.
// this is where the magic happens
}
Service Worker Performance
Service Worker Cache API Browser cache via http headersvs
Consistency Consistency
Speed
Granularity Granularity
Speed
Service Worker Performance ➜ vs Browser cache
Service Worker Performance Tools
fetch(e.request).then(function (response) {
return response;
});
Service Worker Performance ➜ Tools ➜ Fetch
self.addEventListener('fetch', function (e) {
if( e.request.url.indexOf('static.myapp.com') !== -1 ) {
e.respondWith(
// some caching strategy
);
} else {
e.respondWith(
// some other caching strategy
);
}
});
fetch
Service Worker Performance Tools
caches.match(myRequest).then (function (r) {
return r;
});
caches.open('myCacheName').then(function(cache) {
return cache.match(myRequest).then (function (r) {
return r;
});
});
Service Worker Performance ➜ Tools ➜ Cache
cache(s)
caches.open('myCacheName').then(function (cache) {
cache.put(myRequest, myResponse);
…
cache.add(myURL);
…
cache.addAll(myURLsArray);
});
Caching strategies
self.addEventListener('fetch', function (e) {
if(navigator.onLine) {
return;
} else {
e.respondWith(
caches.match(e.request).then(function (r) {
return r })
);
}
});
Network first, fallback cache
Service Worker Performance ➜ Caching strategies
Caching strategies
self.addEventListener('fetch', function (e) {
e.respondWith(
caches.match(e.request).then(function (r) {
if(r) {
return r;
} else {
if(navigator.onLine) {
fetch(e.request).then(function (response) {
caches.open('myCacheName').then(function (cache) {
cache.put(e.request, response.clone());
});
return response;
});
}
}
}));
});
Service Worker Performance ➜ Caching strategies
Cache first, fallback Network then Add to Cache
Caching strategies
self.addEventListener('install', function (e) {
e.waitUntil(
caches.open('myCacheName').then(function (cache) {
for( let i = 0; i < myCacheData.length; i++ ) {
cache.add(myCacheData[i]);
}
// OR: cache.addAll(myCacheData);
})
);
});
self.addEventListener('fetch', function (e) {
e.respondWith(
caches.match(e.request).then(function (r) {
return r })
);
});
Service Worker Performance ➜ Caching strategies
Preload, then Offline
Misurare la Performance dei SW
Service Worker Performance ➜ Misurare
● Synthetic testing
● Real User Monitoring
Synthetic testing
SW supported
SW in document
No SW support
SW in document
SW supported
No SW in document
No SW support
No SW in document
Service Worker Performance ➜ Synthetic testing
First visit Repeat visit
Real User Monitoring
Browser
supports
SW?
Unsupported
Controlled
Supported
SW
controls
page?
Service Worker Performance ➜ Real User Monitoring
'serviceWorker' in navigator?
navigator.serviceWorker.controller?
Impatto
Service Worker Performance ➜ Impatto
da “Measuring the Real-world Performance Impact of Service Workers” by Philip Walton, Google
Impatto
Service Worker Performance ➜ Impatto
Impatto
Service Worker Performance ➜ Impatto
Fonti e approfondimenti
Fonti e approfondimenti ➜ 1/2
Requisito: familiarità con vanilla javascript e l’oggetto promise
●plainJS - The Vanilla JavaScript Repository
●MDN: Promise
PWA
●Google: Your First Progressive Web App
●MDN: Progressive Web Apps
●MDN: Web APIs
●MDN: Manifest
●Manifest generator tool
SW
●MDN: Service Worker API
●Google: Intro to Service Workers
●Google: Service Worker Lifecycle
●Google: Debugging Service Workers
Fetch
●MDN: Using fetch
●MDN: Fetch API
●MDN: FetchEvent
Cache(s)
●Google: Caching Files with Service Worker
●MDN: Cache
●MDN: CacheStorage
Storage limits
●Google: Live Data in the Service Worker
●html5rocks: Working with quota on mobile browsers
●Browser Storage abuser tool
Fonti e approfondimenti ➜ 2/2
On vs. http header caching
●Google: High-performance service worker loading
●Facebook: Web performance: Cache efficiency exercise
Performance
●Google: Measuring the Real-world Performance Impact of Service Workers
●Baqend: Rethinking Web Performance with Service Workers
●PWAStats (fonte inesauribile di dati reali)
Bonus
●MDN: The Service Worker Cookbook (da non perdere la sezione Caching Strategies)
●geddski & Google: Service Workies (un gioco per imparare I Service Workers!)
Fonti e approfondimenti
Turin Web Performance Group
Grazie!
https://twitter.com/ptbello
https://www.facebook.com/piero.bellomo
https://github.com/ptbello/

Mais conteúdo relacionado

Mais procurados

Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in ReactTalentica Software
 
"Technical Challenges behind Visual IDE for React Components" Tetiana Mandziuk
"Technical Challenges behind Visual IDE for React Components" Tetiana Mandziuk"Technical Challenges behind Visual IDE for React Components" Tetiana Mandziuk
"Technical Challenges behind Visual IDE for React Components" Tetiana MandziukFwdays
 
DevQA: make your testers happier with Groovy, Spock and Geb
DevQA: make your testers happier with Groovy, Spock and GebDevQA: make your testers happier with Groovy, Spock and Geb
DevQA: make your testers happier with Groovy, Spock and GebAlvaro Sanchez-Mariscal
 
Service workers and the role they play in modern day web apps
Service workers and the role they play in modern day web appsService workers and the role they play in modern day web apps
Service workers and the role they play in modern day web appsMukul Jain
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMSGavin Pickin
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureMaurice De Beijer [MVP]
 
The complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrrThe complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrrAfreenK
 
Magnolia & Angular JS - an Approach for Javascript RIAs Delivered by a CMS
Magnolia & Angular JS - an Approach for Javascript RIAs Delivered by a CMSMagnolia & Angular JS - an Approach for Javascript RIAs Delivered by a CMS
Magnolia & Angular JS - an Approach for Javascript RIAs Delivered by a CMSMagnolia
 
Using Magnolia in a Microservices Architecture
Using Magnolia in a Microservices ArchitectureUsing Magnolia in a Microservices Architecture
Using Magnolia in a Microservices ArchitectureMagnolia
 
Webpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ StepsWebpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ StepsGrgur Grisogono
 
A Closer Look At React Native
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React NativeIan Wang
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sailsBrian Shannon
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS LimitationsValeri Karpov
 
Exactpro Systems for KSTU Students in Kostroma
Exactpro Systems for KSTU Students in KostromaExactpro Systems for KSTU Students in Kostroma
Exactpro Systems for KSTU Students in KostromaIosif Itkin
 
Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2Mindfire Solutions
 
The Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIThe Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIEdmund Turbin
 

Mais procurados (20)

Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
 
"Technical Challenges behind Visual IDE for React Components" Tetiana Mandziuk
"Technical Challenges behind Visual IDE for React Components" Tetiana Mandziuk"Technical Challenges behind Visual IDE for React Components" Tetiana Mandziuk
"Technical Challenges behind Visual IDE for React Components" Tetiana Mandziuk
 
DevQA: make your testers happier with Groovy, Spock and Geb
DevQA: make your testers happier with Groovy, Spock and GebDevQA: make your testers happier with Groovy, Spock and Geb
DevQA: make your testers happier with Groovy, Spock and Geb
 
Service workers and the role they play in modern day web apps
Service workers and the role they play in modern day web appsService workers and the role they play in modern day web apps
Service workers and the role they play in modern day web apps
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMS
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & Azure
 
The complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrrThe complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrr
 
Magnolia & Angular JS - an Approach for Javascript RIAs Delivered by a CMS
Magnolia & Angular JS - an Approach for Javascript RIAs Delivered by a CMSMagnolia & Angular JS - an Approach for Javascript RIAs Delivered by a CMS
Magnolia & Angular JS - an Approach for Javascript RIAs Delivered by a CMS
 
Using Magnolia in a Microservices Architecture
Using Magnolia in a Microservices ArchitectureUsing Magnolia in a Microservices Architecture
Using Magnolia in a Microservices Architecture
 
Webpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ StepsWebpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ Steps
 
A Closer Look At React Native
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React Native
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
 
Angular beans
Angular beansAngular beans
Angular beans
 
jdays 2015
jdays 2015jdays 2015
jdays 2015
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
 
Exactpro Systems for KSTU Students in Kostroma
Exactpro Systems for KSTU Students in KostromaExactpro Systems for KSTU Students in Kostroma
Exactpro Systems for KSTU Students in Kostroma
 
Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2
 
The Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIThe Themer's Guide to WP-CLI
The Themer's Guide to WP-CLI
 

Semelhante a Service workers - Forza lavoro al servizio della tua Performance

Performance testing with JMeter
Performance testing with JMeterPerformance testing with JMeter
Performance testing with JMeterMikael Kundert
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayPOSSCON
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!Chang W. Doh
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayAll Things Open
 
Sprint 45 review
Sprint 45 reviewSprint 45 review
Sprint 45 reviewManageIQ
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web AppsUnfold UI
 
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...Sencha
 
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond AgileEngineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond AgileKenAtIndeed
 
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUGCreando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUGCésar Hernández
 
How to Create a Service in Choreo
How to Create a Service in ChoreoHow to Create a Service in Choreo
How to Create a Service in ChoreoWSO2
 
Recipes for a successful production cloudfoundry deployment - CF Summit 2014
Recipes for a successful production cloudfoundry deployment - CF Summit 2014Recipes for a successful production cloudfoundry deployment - CF Summit 2014
Recipes for a successful production cloudfoundry deployment - CF Summit 2014Vinícius Carvalho
 
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...VMware Tanzu
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first designKyrylo Reznykov
 
Using Event Streams in Serverless Applications
Using Event Streams in Serverless ApplicationsUsing Event Streams in Serverless Applications
Using Event Streams in Serverless ApplicationsJonathan Dee
 
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScaleGDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScalePatrick Chanezon
 
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019Viktor Todorov
 
Progressive web applications
Progressive web applicationsProgressive web applications
Progressive web applicationsTom Martin
 
Do not automate GUI testing
Do not automate GUI testingDo not automate GUI testing
Do not automate GUI testingAtila Inovecký
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance TestingAnand Bagmar
 

Semelhante a Service workers - Forza lavoro al servizio della tua Performance (20)

Performance testing with JMeter
Performance testing with JMeterPerformance testing with JMeter
Performance testing with JMeter
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
 
Sprint 45 review
Sprint 45 reviewSprint 45 review
Sprint 45 review
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
 
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
 
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond AgileEngineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
Engineering Velocity @indeed eng presented on Sept 24 2014 at Beyond Agile
 
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUGCreando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
 
How to Create a Service in Choreo
How to Create a Service in ChoreoHow to Create a Service in Choreo
How to Create a Service in Choreo
 
Recipes for a successful production cloudfoundry deployment - CF Summit 2014
Recipes for a successful production cloudfoundry deployment - CF Summit 2014Recipes for a successful production cloudfoundry deployment - CF Summit 2014
Recipes for a successful production cloudfoundry deployment - CF Summit 2014
 
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first design
 
Using Event Streams in Serverless Applications
Using Event Streams in Serverless ApplicationsUsing Event Streams in Serverless Applications
Using Event Streams in Serverless Applications
 
GDG Ibadan #pwa
GDG Ibadan #pwaGDG Ibadan #pwa
GDG Ibadan #pwa
 
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScaleGDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
 
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
 
Progressive web applications
Progressive web applicationsProgressive web applications
Progressive web applications
 
Do not automate GUI testing
Do not automate GUI testingDo not automate GUI testing
Do not automate GUI testing
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance Testing
 

Último

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Último (20)

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Service workers - Forza lavoro al servizio della tua Performance

  • 1. Turin Web Performance Group Service Workers Forza lavoro al servizio della tua Performance con Piero Bellomo, @ptbello performance-obsessed full stack dev
  • 2. ● Contesto ● Le PWA ● I Service Worker ● Service Worker Performance ● Fonti e approfondimenti Indice
  • 3. PWA “Progressive Web Applications (PWAs) are web applications that load like regular web pages or websites but can offer functionality traditionally available only to native apps. PWAs combine the open standards of the web to provide benefits of a rich mobile experience.” Wikipedia The Future Native Apps Progressive Web Apps Contesto ➜ Le PWA
  • 4. Native feel ● Add to Home screen ● Hardware access ● Notifiche push ● ...and the list goes on Contesto ➜ Le PWA PWA
  • 5. Native feel ● Add to Home screen ● Hardware access ● Notifiche push ● ...and the list goes on Reliability Modalità offline in funzione della connettività disponibile Contesto ➜ Le PWA PWA
  • 6. Native feel ● Add to Home screen ● Hardware access ● Notifiche push ● ...and the list goes on Reliability Modalità offline in funzione della connettività disponibile Performance Ooooh! Caching! Contesto ➜ Le PWA PWA
  • 7. Gli ingredienti di una PWA ● https:// ● Manifest Contesto ➜ Le PWA ➜ Ingredienti ● APIs ● SW
  • 8. Manifest Contesto ➜ Le PWA ➜ Ingredienti ➜ Manifest …of the Communist Party? Ahem, sorry, No Party.
  • 9. Manifest Un file Json con informazioni utili al (mobile) OS per presentare l’App nelle diverse situazioni Contesto ➜ Le PWA ➜ Ingredienti ➜ Manifest <head> ... <link rel="manifest" href="myapp.webmanifest"> ... </head>
  • 10. APIs Il Presente ● Audio/Video ● Background Sync ● Storage ○ LocalStorage (obsoleto) ○ IndexedDB ○ Cache API ● Fetch (XMLHttpRequest on crack) ● Geolocation ● Notifiche Il Futuro ● Payment Request ● Web Speech ● Web Authentication ● Web Share ● Geofencing? ● Gamepad? Contesto ➜ Le PWA ➜ Ingredienti ➜ APIs
  • 11. Service Worker Contesto ➜ Le PWA ➜ Ingredienti ➜ Service Worker Il Cervello della banda
  • 12. Cos’è un Service Worker ● Background Process può essere idle o active Contesto ➜ il Service Worker ➜ Cos’è
  • 13. Cos’è un Service Worker ● Background Process può essere idle o active ● Network Proxy intercetta richieste con fetch Contesto ➜ il Service Worker ➜ Cos’è
  • 14. Cos’è un Service Worker ● Background Process può essere idle o active ● Network Proxy intercetta richieste con fetch ● No DOM access ma accesso indiretto via postMessage e Clients Contesto ➜ il Service Worker ➜ Cos’è
  • 15. Cos’è un Service Worker ● Background Process può essere idle o active ● Network Proxy intercetta richieste con fetch ● No DOM access ma accesso indiretto via postMessage e Clients ● Persistent Data Access client-side storage con Cache Contesto ➜ il Service Worker ➜ Cos’è
  • 16. Registrazione index.html <head> ... <script src="./app.js"></script> ... </head> if( 'serviceWorker' in navigator ) { navigator.serviceWorker.register('./sw.js'); } else { console.log('serviceWorker not available!); } add Event Listeners ➜ app.js sw.js Contesto ➜ il Service Worker ➜ Registrazione
  • 17. self.addEventListener('install', function(e) { //… do stuff that happens only once // (will also fire if sw is updated) // e.g. cache static assets } Lifecycle Contesto ➜ il Service Worker ➜ Lifecycle
  • 18. self.addEventListener('activate', function(e) { //… do stuff that only need to happen // when you updated to a newer version // e.g. clear/amend cache } Lifecycle Contesto ➜ il Service Worker ➜ Lifecycle
  • 19. Lifecycle Contesto ➜ il Service Worker ➜ Lifecycle self.addEventListener('fetch', function (e) { // intercept and manipulate every. single. request. // this is where the magic happens }
  • 20. Service Worker Performance Service Worker Cache API Browser cache via http headersvs Consistency Consistency Speed Granularity Granularity Speed Service Worker Performance ➜ vs Browser cache
  • 21. Service Worker Performance Tools fetch(e.request).then(function (response) { return response; }); Service Worker Performance ➜ Tools ➜ Fetch self.addEventListener('fetch', function (e) { if( e.request.url.indexOf('static.myapp.com') !== -1 ) { e.respondWith( // some caching strategy ); } else { e.respondWith( // some other caching strategy ); } }); fetch
  • 22. Service Worker Performance Tools caches.match(myRequest).then (function (r) { return r; }); caches.open('myCacheName').then(function(cache) { return cache.match(myRequest).then (function (r) { return r; }); }); Service Worker Performance ➜ Tools ➜ Cache cache(s) caches.open('myCacheName').then(function (cache) { cache.put(myRequest, myResponse); … cache.add(myURL); … cache.addAll(myURLsArray); });
  • 23. Caching strategies self.addEventListener('fetch', function (e) { if(navigator.onLine) { return; } else { e.respondWith( caches.match(e.request).then(function (r) { return r }) ); } }); Network first, fallback cache Service Worker Performance ➜ Caching strategies
  • 24. Caching strategies self.addEventListener('fetch', function (e) { e.respondWith( caches.match(e.request).then(function (r) { if(r) { return r; } else { if(navigator.onLine) { fetch(e.request).then(function (response) { caches.open('myCacheName').then(function (cache) { cache.put(e.request, response.clone()); }); return response; }); } } })); }); Service Worker Performance ➜ Caching strategies Cache first, fallback Network then Add to Cache
  • 25. Caching strategies self.addEventListener('install', function (e) { e.waitUntil( caches.open('myCacheName').then(function (cache) { for( let i = 0; i < myCacheData.length; i++ ) { cache.add(myCacheData[i]); } // OR: cache.addAll(myCacheData); }) ); }); self.addEventListener('fetch', function (e) { e.respondWith( caches.match(e.request).then(function (r) { return r }) ); }); Service Worker Performance ➜ Caching strategies Preload, then Offline
  • 26. Misurare la Performance dei SW Service Worker Performance ➜ Misurare ● Synthetic testing ● Real User Monitoring
  • 27. Synthetic testing SW supported SW in document No SW support SW in document SW supported No SW in document No SW support No SW in document Service Worker Performance ➜ Synthetic testing First visit Repeat visit
  • 28. Real User Monitoring Browser supports SW? Unsupported Controlled Supported SW controls page? Service Worker Performance ➜ Real User Monitoring 'serviceWorker' in navigator? navigator.serviceWorker.controller?
  • 29. Impatto Service Worker Performance ➜ Impatto da “Measuring the Real-world Performance Impact of Service Workers” by Philip Walton, Google
  • 32. Fonti e approfondimenti Fonti e approfondimenti ➜ 1/2 Requisito: familiarità con vanilla javascript e l’oggetto promise ●plainJS - The Vanilla JavaScript Repository ●MDN: Promise PWA ●Google: Your First Progressive Web App ●MDN: Progressive Web Apps ●MDN: Web APIs ●MDN: Manifest ●Manifest generator tool SW ●MDN: Service Worker API ●Google: Intro to Service Workers ●Google: Service Worker Lifecycle ●Google: Debugging Service Workers Fetch ●MDN: Using fetch ●MDN: Fetch API ●MDN: FetchEvent Cache(s) ●Google: Caching Files with Service Worker ●MDN: Cache ●MDN: CacheStorage Storage limits ●Google: Live Data in the Service Worker ●html5rocks: Working with quota on mobile browsers ●Browser Storage abuser tool
  • 33. Fonti e approfondimenti ➜ 2/2 On vs. http header caching ●Google: High-performance service worker loading ●Facebook: Web performance: Cache efficiency exercise Performance ●Google: Measuring the Real-world Performance Impact of Service Workers ●Baqend: Rethinking Web Performance with Service Workers ●PWAStats (fonte inesauribile di dati reali) Bonus ●MDN: The Service Worker Cookbook (da non perdere la sezione Caching Strategies) ●geddski & Google: Service Workies (un gioco per imparare I Service Workers!) Fonti e approfondimenti
  • 34. Turin Web Performance Group Grazie! https://twitter.com/ptbello https://www.facebook.com/piero.bellomo https://github.com/ptbello/