SlideShare ist ein Scribd-Unternehmen logo
1 von 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/

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 

Kürzlich hochgeladen (20)

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 

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/