SlideShare a Scribd company logo
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/

More Related Content

What's hot

Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
Talentica 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 Mandziuk
Fwdays
 
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
Alvaro 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 apps
Mukul Jain
 
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
Maurice De Beijer [MVP]
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMS
Gavin 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 & Azure
Maurice 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 dyrr
AfreenK
 
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
Magnolia
 
Using Magnolia in a Microservices Architecture
Using Magnolia in a Microservices ArchitectureUsing Magnolia in a Microservices Architecture
Using Magnolia in a Microservices Architecture
Magnolia
 
Webpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ StepsWebpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ Steps
Grgur Grisogono
 
A Closer Look At React Native
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React Native
Ian Wang
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
Brian Shannon
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
Valeri Karpov
 
Angular beans
Angular beansAngular beans
Angular beans
Bessem Hmidi
 
jdays 2015
jdays 2015jdays 2015
jdays 2015
Joe Kutner
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
Talentica Software
 
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 2
Mindfire 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-CLI
Edmund Turbin
 

What's hot (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
 

Similar to Service workers - Forza lavoro al servizio della tua Performance

Performance testing with JMeter
Performance testing with JMeterPerformance testing with JMeter
Performance testing with JMeter
Mikael 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 Anyway
POSSCON
 
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 Anyway
All Things Open
 
Sprint 45 review
Sprint 45 reviewSprint 45 review
Sprint 45 review
ManageIQ
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
Unfold 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 Agile
KenAtIndeed
 
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
Cé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 Choreo
WSO2
 
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
 
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
Vinícius Carvalho
 
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
Kyrylo Reznykov
 
Using Event Streams in Serverless Applications
Using Event Streams in Serverless ApplicationsUsing Event Streams in Serverless Applications
Using Event Streams in Serverless Applications
Jonathan Dee
 
GDG Ibadan #pwa
GDG Ibadan #pwaGDG Ibadan #pwa
GDG Ibadan #pwa
Gbolahan Alli
 
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
Patrick 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 2019
Viktor Todorov
 
Progressive web applications
Progressive web applicationsProgressive web applications
Progressive web applications
Tom Martin
 
Do not automate GUI testing
Do not automate GUI testingDo not automate GUI testing
Do not automate GUI testing
Atila Inovecký
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance Testing
Anand Bagmar
 

Similar to 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
 
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 ...
 
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
 
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
 

Recently uploaded

Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 

Recently uploaded (20)

Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 

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/