Mateusz Krzyżanowski: Jak wykorzystać Progressive Web App by nasza webowa aplikacja stała się czymś więcej niż zwykłą stroną internetową? Prezentacja będzie wprowadzeniem w możliwości i dobrodziejstwa jakie daje nam PWA. Porozmawiamy o tym jak zacząć i z jakich narzędzi korzystać.
2. BRING YOUR WEB APP TO THE NEXT LEVEL
„Progressive Web Apps are the future of all
mankind. They’ll bring world peace, end hunger,
save the rainbows and unicorns, bring balance to
the force, and a whole lot more”
ionic blog
3. BRING YOUR WEB APP TO THE NEXT LEVEL
ALE O CO CHODZI?
”A Progressive Web App uses modern web
capabilities to deliver an app-like user experience.”
18. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #2
CO JEŚLI NIE TWORZĘ APLIKACJI OD ZERA?
19. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #2 - MIGRACJA
▸ kompresja (style, grafika…)
▸ optymalizacja (usunięcie zbędnego kodu, unikanie
blokującego kodu…)
▸ podzielenie dużych plików js na mniejsze (np. dynamic
imports)
20. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #3
SERVICE WORKERS
22. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #3 - STRATEGIE
23. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #3 - SERVICE WORKER W AKCJI
...
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js')
.then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
...
24. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #3 - SERVICE WORKER W AKCJI
...
const VERSION = 'v1';
const urlsToCache = [
'/',
'/styles/main.css',
'/script/main.js'
];
self.addEventListener('install', function(event) {
// Perform install steps
event.waitUntil(
caches.open(VERSION)
.then(function(cache) {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
25. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #3 - SERVICE WORKER W AKCJI
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.open('mysite-dynamic').then(function(cache) {
return cache.match(event.request).then(function (response) {
return response || fetch(event.request).then(function(response) {
cache.put(event.request, response.clone());
return response;
});
});
})
);
});
26. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #3 - SERVICE WORKER W AKCJI
27. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #4
APP MANIFEST
<link rel="manifest" href="/manifest.json">
28. BRING YOUR WEB APP TO THE NEXT LEVEL
KROK #4 - APP MANIFEST PRZYKŁAD
{
"name": "My test application",
"short_name": "My app",
"icons": [
{
"src": "/assets/icons/favicon-32x32.png",
"sizes": "32x32",
"type": "image/png"
},
{
"src": "/assets/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
}
],
"background_color": "#ffa500",
"theme_color": "#ffffff”,
"orientation": "portrait”,
"display": "standalone",
"start_url": "/index.html"
}
49. BRING YOUR WEB APP TO THE NEXT LEVEL
PODSUMOWANIE
▸ https - app shell - service worker - manifest
▸ offline
▸ auto-aktualizacja
▸ szybkość
▸ oddziaływanie na użytkownika
50. BRING YOUR WEB APP TO THE NEXT LEVEL
PRZYDATNE LINKI
https://www.smashingmagazine.com/2016/08/a-beginners-guide-to-progressive-web-apps/
https://developers.google.com/web/ilt/pwa/introduction-to-progressive-web-app-architectures
https://jakearchibald.com/2014/offline-cookbook/#serving-suggestions-responding-to-requests
https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/
https://www.youtube.com/watch?v=KRSTpo6gqqU
https://www.youtube.com/watch?v=eodArdGRIVQ
https://www.youtube.com/watch?v=zuGE3eFQD9I