SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
Stanco delle solite
web app? Passa al
Progressive!
Federico “Edo” Granata
By
Hello World!
Io sono Federico “Edo” Granata
Potete trovarmi su
https://federicogranata.dev
1
Progressive Web App
Non facciamoci
intimorire
Le caratteristiche di una PWA
Veloce
Secondo un
sorprendente
sondaggio gli
utenti non
apprezzano le app
lente.
Affidabile
L’utente deve
poter interagire
a prescindere
dalle condizioni
di rete.
Accattivante
Una PWA è
installabile,
offre
un’esperienza
full-screen e
consente di usare
push
notifications.
... ma in pratica?
HTTPS
Tutto il traffico
DEVE essere
cifrato.
Manifest
Un semplice file
per indicare al
browser che ha a
che fare con una
PWA.
Service Worker
Un JS in cui
avviene la magia
che consente di
gestire cache e
notifiche push.
<link rel="manifest" href="/manifest.json">
{
"short_name": "Maps",
"name": "Google Maps",
"icons": [
{
"src": "/images/icons-192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/images/icons-512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": "/pwa/?source=pwa",
"scope": "/pwa/",
"display": "standalone",
"background_color": "#123456",
"theme_color": "#FEDCBA"
}
Manifest.json
Service Worker
▪ JavaScript
▪ Separato dalla pagina
▪ Background
▪ Event Driven
▪ Magia
... magia?
PRO
▪ Programmable Proxy
▪ Background Sync
▪ Push Notifications
CONTRO
▪ DOM
▪ Nessuna persistenza
Programmable Proxy
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});
Service Worker LifeCycle
▪ .register()
▪ Evento install
▪ Una promise viene passata a
installEvent.waitUntil()
▪ Un service worker non riceve eventi e
push fino a quando diventa "active".
▪ Le richieste di una pagina non passano da
un service worker a meno che la pagina
stessa sia passata da un service worker
▪ clients.claim() può prendere il controllo
immediatamente
<!DOCTYPE html>
An image will appear here in 3 seconds:
<script>
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('SW registered!', reg))
.catch(err => console.log('Boo!', err));
setTimeout(() => {
const img = new Image();
img.src = '/dog.svg';
document.body.appendChild(img);
}, 3000);
</script>
self.addEventListener('install', event => {
event.waitUntil(
caches.open('static-v1').then(fuction(cache) {
cache.add('/cat.svg');
});
);
});
self.addEventListener('activate', event => {
console.log('ready');
});
self.addEventListener('fetch', event => {
const url = new URL(event.request.url);
if (url.origin == location.origin &&
url.pathname == '/dog.svg') {
event.respondWith(caches.match('/cat.svg'));
}
});
DEMO 1 DEMO 2
Service Worker Update
▪ Download nuovo SW
▪ Eseguito in parallelo (riceve il
suo evento install)
▪ Attende che la precedente
versione non sia più in uso
▪ Oppure self.skipWaiting()
Made Easy
Workbox is a library that bakes in
a set of best practices and removes
the boilerplate every developer
writes when working with service
workers.
Workbox
▪ Precaching
▪ Runtime caching
▪ Strategies
▪ Request routing
▪ Background sync
▪ Helpful debugging
▪ Greater flexibility and feature
set than sw-precache and
sw-toolbox
Workbox Programmable Proxy - Basic
workbox.routing.registerRoute(
/.(?:js|css)$/,
new workbox.strategies.StaleWhileRevalidate(),
);
Workbox Programmable Proxy - Intermediate
workbox.routing.registerRoute(
/.(?:png|gif|jpg|jpeg|svg)$/,
new workbox.strategies.CacheFirst({
cacheName: 'images',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
}),
],
}),
);
Workbox Programmable Proxy - Advanced
workbox.routing.registerRoute(
/^https://fonts.gstatic.com/,
new workbox.strategies.CacheFirst({
cacheName: 'google-fonts-webfonts',
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [0, 200],
}),
new workbox.expiration.Plugin({
maxAgeSeconds: 60 * 60 * 24 * 365,
}),
],
}),
);
Workbox Background Sync
const bgSyncPlugin = new
workbox.backgroundSync.Plugin('myQueueName', {
maxRetentionTime: 24 * 60 // Retry for max of 24 Hours
});
workbox.routing.registerRoute(
//api/.*/*.json/,
new workbox.strategies.NetworkOnly({
plugins: [bgSyncPlugin]
}),
'POST'
);
Workbox offre molto altro
▪ 13 moduli Service Worker
▪ 1 modulo Window
▪ Tools per automatizzare (cli,
npm, gulp, grunt e webpack)
Risorse Utili
▪ Manifest - http://bit.ly/313G047
▪ Install - http://bit.ly/311fYOZ
▪ Service Worker - http://bit.ly/2KqBU03
▪ SW LyfeCycle - http://bit.ly/30Hjuxb
▪ Workbox - http://bit.ly/311EAr5
▪ PWA Starter Kit - http://bit.ly/2JU1Wau
▪ Bento Starter - http://bit.ly/2JC4ZVI
▪ PWA Checklist - http://bit.ly/313GtTV
Thanks!
ANY QUESTIONS?
You can find me at:
federico.granata@gmail.com
https://federicogranata.dev
http://bit.ly/Edo-LinkedIn
CREDITS
Special thanks to all the people who made and released
these awesome resources for free:
▪ Presentation template by SlidesCarnival

Mais conteúdo relacionado

Mais procurados

Gae piattaforma su cloud
Gae piattaforma su cloudGae piattaforma su cloud
Gae piattaforma su cloud
masci
 
Ignite IBB: Gabriele Loiacono - qube-os un sistema operativo web based per sv...
Ignite IBB: Gabriele Loiacono - qube-os un sistema operativo web based per sv...Ignite IBB: Gabriele Loiacono - qube-os un sistema operativo web based per sv...
Ignite IBB: Gabriele Loiacono - qube-os un sistema operativo web based per sv...
Toscanalab
 

Mais procurados (11)

Workflow Dev-Test-Live per WordPress
Workflow Dev-Test-Live per WordPressWorkflow Dev-Test-Live per WordPress
Workflow Dev-Test-Live per WordPress
 
Task automation with grunt
Task automation with gruntTask automation with grunt
Task automation with grunt
 
Cloud DB, il Database as a Service di Seeweb
Cloud DB, il Database as a Service di SeewebCloud DB, il Database as a Service di Seeweb
Cloud DB, il Database as a Service di Seeweb
 
Gae piattaforma su cloud
Gae piattaforma su cloudGae piattaforma su cloud
Gae piattaforma su cloud
 
node.js e Postgresql
node.js e Postgresqlnode.js e Postgresql
node.js e Postgresql
 
Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010
 
Java EE facile con Spring Boot - Luigi Bennardis - Codemotion Roma 2015
Java EE facile con Spring Boot - Luigi Bennardis - Codemotion Roma 2015Java EE facile con Spring Boot - Luigi Bennardis - Codemotion Roma 2015
Java EE facile con Spring Boot - Luigi Bennardis - Codemotion Roma 2015
 
Madaudo
MadaudoMadaudo
Madaudo
 
SUE AGILE Architettura (Italiano)
SUE AGILE Architettura (Italiano)SUE AGILE Architettura (Italiano)
SUE AGILE Architettura (Italiano)
 
SLA Confidential
SLA ConfidentialSLA Confidential
SLA Confidential
 
Ignite IBB: Gabriele Loiacono - qube-os un sistema operativo web based per sv...
Ignite IBB: Gabriele Loiacono - qube-os un sistema operativo web based per sv...Ignite IBB: Gabriele Loiacono - qube-os un sistema operativo web based per sv...
Ignite IBB: Gabriele Loiacono - qube-os un sistema operativo web based per sv...
 

Semelhante a Stanco delle solite Web App? Passa al Prgressive

Come sviluppare applicazioni cross device con HTML
Come sviluppare applicazioni cross device con HTMLCome sviluppare applicazioni cross device con HTML
Come sviluppare applicazioni cross device con HTML
Sinergia Totale
 
OCP-Architettura e caratteristiche della PaaS
OCP-Architettura e caratteristiche della PaaSOCP-Architettura e caratteristiche della PaaS
OCP-Architettura e caratteristiche della PaaS
opencityplatform
 
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
Corso WebApp iOS - Lezione 06:   Web Development for iOS DevicesCorso WebApp iOS - Lezione 06:   Web Development for iOS Devices
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
Andrea Picchi
 
JAMP DAY 2010 - ROMA (1)
JAMP DAY 2010 - ROMA (1)JAMP DAY 2010 - ROMA (1)
JAMP DAY 2010 - ROMA (1)
jampslide
 

Semelhante a Stanco delle solite Web App? Passa al Prgressive (20)

Meetup Fluent Design e Progressive Web App
Meetup Fluent Design e Progressive Web AppMeetup Fluent Design e Progressive Web App
Meetup Fluent Design e Progressive Web App
 
Meetup Progressive Web App
Meetup Progressive Web AppMeetup Progressive Web App
Meetup Progressive Web App
 
Working between the clouds (versione completa)
Working between the clouds (versione completa)Working between the clouds (versione completa)
Working between the clouds (versione completa)
 
Un backend per tutte le stagioni con Spring
Un backend per tutte le stagioni con SpringUn backend per tutte le stagioni con Spring
Un backend per tutte le stagioni con Spring
 
Esposizione RIA
Esposizione RIAEsposizione RIA
Esposizione RIA
 
Working between the clouds
Working between the cloudsWorking between the clouds
Working between the clouds
 
Come sviluppare applicazioni cross device con HTML
Come sviluppare applicazioni cross device con HTMLCome sviluppare applicazioni cross device con HTML
Come sviluppare applicazioni cross device con HTML
 
Creare PWA con Angular
Creare PWA con AngularCreare PWA con Angular
Creare PWA con Angular
 
Spring E Spring Web Flow Nel Progetto Jug Avis Web
Spring E Spring Web Flow Nel Progetto Jug Avis WebSpring E Spring Web Flow Nel Progetto Jug Avis Web
Spring E Spring Web Flow Nel Progetto Jug Avis Web
 
Applicazioni Web ultra-performanti con Vue.js e Delphi
Applicazioni Web ultra-performanti con Vue.js e DelphiApplicazioni Web ultra-performanti con Vue.js e Delphi
Applicazioni Web ultra-performanti con Vue.js e Delphi
 
Open Source Day 2015 - DBaaS con Docker: un caso di studio
Open Source Day 2015 - DBaaS con Docker: un caso di studioOpen Source Day 2015 - DBaaS con Docker: un caso di studio
Open Source Day 2015 - DBaaS con Docker: un caso di studio
 
Notes for an Enterprise Scheduling Distributed Application
Notes for an Enterprise Scheduling Distributed ApplicationNotes for an Enterprise Scheduling Distributed Application
Notes for an Enterprise Scheduling Distributed Application
 
OCP-Architettura e caratteristiche della PaaS
OCP-Architettura e caratteristiche della PaaSOCP-Architettura e caratteristiche della PaaS
OCP-Architettura e caratteristiche della PaaS
 
Infrastructure as Data
Infrastructure as DataInfrastructure as Data
Infrastructure as Data
 
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
Corso WebApp iOS - Lezione 06:   Web Development for iOS DevicesCorso WebApp iOS - Lezione 06:   Web Development for iOS Devices
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
 
JAMP DAY 2010 - ROMA (1)
JAMP DAY 2010 - ROMA (1)JAMP DAY 2010 - ROMA (1)
JAMP DAY 2010 - ROMA (1)
 
Acadevmy - PWA Overview
Acadevmy - PWA OverviewAcadevmy - PWA Overview
Acadevmy - PWA Overview
 
Yagwto
YagwtoYagwto
Yagwto
 
Acadevmy - PWA & Angular
Acadevmy - PWA & AngularAcadevmy - PWA & Angular
Acadevmy - PWA & Angular
 
OCP Paas_ultima
OCP Paas_ultimaOCP Paas_ultima
OCP Paas_ultima
 

Mais de Commit University

Mais de Commit University (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdfBreaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
 
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdfAccelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
 
Slide-10years.pdf
Slide-10years.pdfSlide-10years.pdf
Slide-10years.pdf
 
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
 
Vue.js slots.pdf
Vue.js slots.pdfVue.js slots.pdf
Vue.js slots.pdf
 
Commit - Qwik il framework che ti stupirà.pptx
Commit - Qwik il framework che ti stupirà.pptxCommit - Qwik il framework che ti stupirà.pptx
Commit - Qwik il framework che ti stupirà.pptx
 
Sviluppare da zero una Angular Web App per la PA
Sviluppare da zero una Angular Web App per la PASviluppare da zero una Angular Web App per la PA
Sviluppare da zero una Angular Web App per la PA
 
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
 
Prisma the ORM that node was waiting for
Prisma the ORM that node was waiting forPrisma the ORM that node was waiting for
Prisma the ORM that node was waiting for
 
Decision-making for Software Development Teams - Commit University
Decision-making for Software Development Teams - Commit UniversityDecision-making for Software Development Teams - Commit University
Decision-making for Software Development Teams - Commit University
 
Component Design Pattern nei Game Engine.pdf
Component Design Pattern nei Game Engine.pdfComponent Design Pattern nei Game Engine.pdf
Component Design Pattern nei Game Engine.pdf
 
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
 
Prototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step FunctionsPrototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step Functions
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and Swift
 
Da Vuex a Pinia: come fare la migrazione
Da Vuex a Pinia: come fare la migrazioneDa Vuex a Pinia: come fare la migrazione
Da Vuex a Pinia: come fare la migrazione
 
Orchestrare Micro-frontend con micro-lc
Orchestrare Micro-frontend con micro-lcOrchestrare Micro-frontend con micro-lc
Orchestrare Micro-frontend con micro-lc
 
Fastify has defeated Lagacy-Code
Fastify has defeated Lagacy-CodeFastify has defeated Lagacy-Code
Fastify has defeated Lagacy-Code
 
SwiftUI vs UIKit
SwiftUI vs UIKitSwiftUI vs UIKit
SwiftUI vs UIKit
 

Stanco delle solite Web App? Passa al Prgressive

  • 1. Stanco delle solite web app? Passa al Progressive! Federico “Edo” Granata By
  • 2. Hello World! Io sono Federico “Edo” Granata Potete trovarmi su https://federicogranata.dev
  • 3. 1 Progressive Web App Non facciamoci intimorire
  • 4. Le caratteristiche di una PWA Veloce Secondo un sorprendente sondaggio gli utenti non apprezzano le app lente. Affidabile L’utente deve poter interagire a prescindere dalle condizioni di rete. Accattivante Una PWA è installabile, offre un’esperienza full-screen e consente di usare push notifications.
  • 5. ... ma in pratica? HTTPS Tutto il traffico DEVE essere cifrato. Manifest Un semplice file per indicare al browser che ha a che fare con una PWA. Service Worker Un JS in cui avviene la magia che consente di gestire cache e notifiche push.
  • 6. <link rel="manifest" href="/manifest.json"> { "short_name": "Maps", "name": "Google Maps", "icons": [ { "src": "/images/icons-192.png", "type": "image/png", "sizes": "192x192" }, { "src": "/images/icons-512.png", "type": "image/png", "sizes": "512x512" } ], "start_url": "/pwa/?source=pwa", "scope": "/pwa/", "display": "standalone", "background_color": "#123456", "theme_color": "#FEDCBA" } Manifest.json
  • 7. Service Worker ▪ JavaScript ▪ Separato dalla pagina ▪ Background ▪ Event Driven ▪ Magia
  • 8. ... magia? PRO ▪ Programmable Proxy ▪ Background Sync ▪ Push Notifications CONTRO ▪ DOM ▪ Nessuna persistenza
  • 9. Programmable Proxy self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request) .then(function(response) { // Cache hit - return response if (response) { return response; } return fetch(event.request); } ) ); });
  • 10. Service Worker LifeCycle ▪ .register() ▪ Evento install ▪ Una promise viene passata a installEvent.waitUntil() ▪ Un service worker non riceve eventi e push fino a quando diventa "active". ▪ Le richieste di una pagina non passano da un service worker a meno che la pagina stessa sia passata da un service worker ▪ clients.claim() può prendere il controllo immediatamente
  • 11. <!DOCTYPE html> An image will appear here in 3 seconds: <script> navigator.serviceWorker.register('/sw.js') .then(reg => console.log('SW registered!', reg)) .catch(err => console.log('Boo!', err)); setTimeout(() => { const img = new Image(); img.src = '/dog.svg'; document.body.appendChild(img); }, 3000); </script>
  • 12. self.addEventListener('install', event => { event.waitUntil( caches.open('static-v1').then(fuction(cache) { cache.add('/cat.svg'); }); ); }); self.addEventListener('activate', event => { console.log('ready'); }); self.addEventListener('fetch', event => { const url = new URL(event.request.url); if (url.origin == location.origin && url.pathname == '/dog.svg') { event.respondWith(caches.match('/cat.svg')); } }); DEMO 1 DEMO 2
  • 13. Service Worker Update ▪ Download nuovo SW ▪ Eseguito in parallelo (riceve il suo evento install) ▪ Attende che la precedente versione non sia più in uso ▪ Oppure self.skipWaiting()
  • 14. Made Easy Workbox is a library that bakes in a set of best practices and removes the boilerplate every developer writes when working with service workers.
  • 15. Workbox ▪ Precaching ▪ Runtime caching ▪ Strategies ▪ Request routing ▪ Background sync ▪ Helpful debugging ▪ Greater flexibility and feature set than sw-precache and sw-toolbox
  • 16. Workbox Programmable Proxy - Basic workbox.routing.registerRoute( /.(?:js|css)$/, new workbox.strategies.StaleWhileRevalidate(), );
  • 17. Workbox Programmable Proxy - Intermediate workbox.routing.registerRoute( /.(?:png|gif|jpg|jpeg|svg)$/, new workbox.strategies.CacheFirst({ cacheName: 'images', plugins: [ new workbox.expiration.Plugin({ maxEntries: 60, maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days }), ], }), );
  • 18. Workbox Programmable Proxy - Advanced workbox.routing.registerRoute( /^https://fonts.gstatic.com/, new workbox.strategies.CacheFirst({ cacheName: 'google-fonts-webfonts', plugins: [ new workbox.cacheableResponse.Plugin({ statuses: [0, 200], }), new workbox.expiration.Plugin({ maxAgeSeconds: 60 * 60 * 24 * 365, }), ], }), );
  • 19. Workbox Background Sync const bgSyncPlugin = new workbox.backgroundSync.Plugin('myQueueName', { maxRetentionTime: 24 * 60 // Retry for max of 24 Hours }); workbox.routing.registerRoute( //api/.*/*.json/, new workbox.strategies.NetworkOnly({ plugins: [bgSyncPlugin] }), 'POST' );
  • 20. Workbox offre molto altro ▪ 13 moduli Service Worker ▪ 1 modulo Window ▪ Tools per automatizzare (cli, npm, gulp, grunt e webpack)
  • 21. Risorse Utili ▪ Manifest - http://bit.ly/313G047 ▪ Install - http://bit.ly/311fYOZ ▪ Service Worker - http://bit.ly/2KqBU03 ▪ SW LyfeCycle - http://bit.ly/30Hjuxb ▪ Workbox - http://bit.ly/311EAr5 ▪ PWA Starter Kit - http://bit.ly/2JU1Wau ▪ Bento Starter - http://bit.ly/2JC4ZVI ▪ PWA Checklist - http://bit.ly/313GtTV
  • 22. Thanks! ANY QUESTIONS? You can find me at: federico.granata@gmail.com https://federicogranata.dev http://bit.ly/Edo-LinkedIn
  • 23. CREDITS Special thanks to all the people who made and released these awesome resources for free: ▪ Presentation template by SlidesCarnival