ݺߣ

ݺߣShare a Scribd company logo
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 = /commitsoftware/stanco-delle-solite-web-app-passa-al-prgressive/&
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 ݺߣsCarnival

More Related Content

What's hot (11)

Workflow Dev-Test-Live per WordPress
Workflow Dev-Test-Live per WordPressWorkflow Dev-Test-Live per WordPress
Workflow Dev-Test-Live per WordPress
Farnedi ICT srl
Task automation with grunt
Task automation with gruntTask automation with grunt
Task automation with grunt
lucatume
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
seeweb
Gae piattaforma su cloud
Gae piattaforma su cloudGae piattaforma su cloud
Gae piattaforma su cloud
masci
node.js e Postgresql
node.js e Postgresqlnode.js e Postgresql
node.js e Postgresql
Lucio Grenzi
Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010
Mauro Servienti
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
Codemotion
SUE AGILE Architettura (Italiano)
SUE AGILE Architettura (Italiano)SUE AGILE Architettura (Italiano)
SUE AGILE Architettura (Italiano)
Sabino Labarile
SLA Confidential
SLA ConfidentialSLA Confidential
SLA Confidential
VMUG IT
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
Workflow Dev-Test-Live per WordPress
Workflow Dev-Test-Live per WordPressWorkflow Dev-Test-Live per WordPress
Workflow Dev-Test-Live per WordPress
Farnedi ICT srl
Task automation with grunt
Task automation with gruntTask automation with grunt
Task automation with grunt
lucatume
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
seeweb
Gae piattaforma su cloud
Gae piattaforma su cloudGae piattaforma su cloud
Gae piattaforma su cloud
masci
Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010
Mauro Servienti
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
Codemotion
SUE AGILE Architettura (Italiano)
SUE AGILE Architettura (Italiano)SUE AGILE Architettura (Italiano)
SUE AGILE Architettura (Italiano)
Sabino Labarile
SLA Confidential
SLA ConfidentialSLA Confidential
SLA Confidential
VMUG IT
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

Similar to 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
dotnetcode
Meetup Progressive Web App
Meetup Progressive Web AppMeetup Progressive Web App
Meetup Progressive Web App
dotnetcode
Working between the clouds (versione completa)
Working between the clouds (versione completa)Working between the clouds (versione completa)
Working between the clouds (versione completa)
Davide Cerbo
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
Marcello Teodori
Esposizione RIA
Esposizione RIAEsposizione RIA
Esposizione RIA
diodorato
Working between the clouds
Working between the cloudsWorking between the clouds
Working between the clouds
Davide Cerbo
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
Creare PWA con Angular
Creare PWA con AngularCreare PWA con Angular
Creare PWA con Angular
Francesco Sciuti
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
Massimiliano Dessì
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
Marco Breveglieri
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
Par-Tec S.p.A.
OCP-Architettura e caratteristiche della PaaS
OCP-Architettura e caratteristiche della PaaSOCP-Architettura e caratteristiche della PaaS
OCP-Architettura e caratteristiche della PaaS
opencityplatform
Infrastructure as Data
Infrastructure as DataInfrastructure as Data
Infrastructure as Data
Francesco Collova'
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
Acadevmy - PWA Overview
Acadevmy - PWA OverviewAcadevmy - PWA Overview
Acadevmy - PWA Overview
Francesco Sciuti
Yagwto
YagwtoYagwto
Yagwto
maraexception
Acadevmy - PWA & Angular
Acadevmy - PWA & AngularAcadevmy - PWA & Angular
Acadevmy - PWA & Angular
Francesco Sciuti
OCP Paas_ultima
OCP Paas_ultimaOCP Paas_ultima
OCP Paas_ultima
opencityplatform
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
dotnetcode
Meetup Progressive Web App
Meetup Progressive Web AppMeetup Progressive Web App
Meetup Progressive Web App
dotnetcode
Working between the clouds (versione completa)
Working between the clouds (versione completa)Working between the clouds (versione completa)
Working between the clouds (versione completa)
Davide Cerbo
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
Marcello Teodori
Working between the clouds
Working between the cloudsWorking between the clouds
Working between the clouds
Davide Cerbo
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
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
Massimiliano Dessì
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
Marco Breveglieri
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
Par-Tec S.p.A.
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

More from Commit University (20)

Contract Driven Development - Branch 2024.pdf
Contract Driven Development - Branch 2024.pdfContract Driven Development - Branch 2024.pdf
Contract Driven Development - Branch 2024.pdf
Commit University
Cybersecurity & AI: Illusioni e Speranze
Cybersecurity & AI: Illusioni e SperanzeCybersecurity & AI: Illusioni e Speranze
Cybersecurity & AI: Illusioni e Speranze
Commit University
Migliorare la Developer Experience in un mondo Cloud Native
Migliorare la Developer Experience in un mondo Cloud NativeMigliorare la Developer Experience in un mondo Cloud Native
Migliorare la Developer Experience in un mondo Cloud Native
Commit University
Scopri come sfruttare la potenza della Hybrid RAG
Scopri come sfruttare la potenza della Hybrid RAGScopri come sfruttare la potenza della Hybrid RAG
Scopri come sfruttare la potenza della Hybrid RAG
Commit University
Introduzione a AWS Forecast e SageMaker DeepAR: Prevedere la Domanda con il M...
Introduzione a AWS Forecast e SageMaker DeepAR: Prevedere la Domanda con il M...Introduzione a AWS Forecast e SageMaker DeepAR: Prevedere la Domanda con il M...
Introduzione a AWS Forecast e SageMaker DeepAR: Prevedere la Domanda con il M...
Commit University
Oltre l'hype: vulnerabilità e limiti dell'intelligenza artificiale.pdf
Oltre l'hype: vulnerabilità e limiti dell'intelligenza artificiale.pdfOltre l'hype: vulnerabilità e limiti dell'intelligenza artificiale.pdf
Oltre l'hype: vulnerabilità e limiti dell'intelligenza artificiale.pdf
Commit University
Alla scoperta dei Vector Database e dei RAG
Alla scoperta dei Vector Database e dei RAGAlla scoperta dei Vector Database e dei RAG
Alla scoperta dei Vector Database e dei RAG
Commit University
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!
Commit University
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)
Commit University
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
Commit University
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-ݺߣ.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-ݺߣ.pdfAccelerating API Development: A Pit Stop with Gin-Gonic in Golang-ݺߣ.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-ݺߣ.pdf
Commit University
ݺߣ-10years.pdf
ݺߣ-10years.pdfݺߣ-10years.pdf
ݺߣ-10years.pdf
Commit University
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 ...
Commit University
Vue.js slots.pdf
Vue.js slots.pdfVue.js slots.pdf
Vue.js slots.pdf
Commit University
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
Commit University
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
Commit University
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 ...
Commit University
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
Commit University
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
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
Commit University
Contract Driven Development - Branch 2024.pdf
Contract Driven Development - Branch 2024.pdfContract Driven Development - Branch 2024.pdf
Contract Driven Development - Branch 2024.pdf
Commit University
Cybersecurity & AI: Illusioni e Speranze
Cybersecurity & AI: Illusioni e SperanzeCybersecurity & AI: Illusioni e Speranze
Cybersecurity & AI: Illusioni e Speranze
Commit University
Migliorare la Developer Experience in un mondo Cloud Native
Migliorare la Developer Experience in un mondo Cloud NativeMigliorare la Developer Experience in un mondo Cloud Native
Migliorare la Developer Experience in un mondo Cloud Native
Commit University
Scopri come sfruttare la potenza della Hybrid RAG
Scopri come sfruttare la potenza della Hybrid RAGScopri come sfruttare la potenza della Hybrid RAG
Scopri come sfruttare la potenza della Hybrid RAG
Commit University
Introduzione a AWS Forecast e SageMaker DeepAR: Prevedere la Domanda con il M...
Introduzione a AWS Forecast e SageMaker DeepAR: Prevedere la Domanda con il M...Introduzione a AWS Forecast e SageMaker DeepAR: Prevedere la Domanda con il M...
Introduzione a AWS Forecast e SageMaker DeepAR: Prevedere la Domanda con il M...
Commit University
Oltre l'hype: vulnerabilità e limiti dell'intelligenza artificiale.pdf
Oltre l'hype: vulnerabilità e limiti dell'intelligenza artificiale.pdfOltre l'hype: vulnerabilità e limiti dell'intelligenza artificiale.pdf
Oltre l'hype: vulnerabilità e limiti dell'intelligenza artificiale.pdf
Commit University
Alla scoperta dei Vector Database e dei RAG
Alla scoperta dei Vector Database e dei RAGAlla scoperta dei Vector Database e dei RAG
Alla scoperta dei Vector Database e dei RAG
Commit University
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!
Commit University
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)
Commit University
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
Commit University
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-ݺߣ.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-ݺߣ.pdfAccelerating API Development: A Pit Stop with Gin-Gonic in Golang-ݺߣ.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-ݺߣ.pdf
Commit University
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 ...
Commit University
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
Commit University
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
Commit University
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 ...
Commit University
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
Commit University
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
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
Commit University

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 = /commitsoftware/stanco-delle-solite-web-app-passa-al-prgressive/& 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 ݺߣsCarnival