Progressive Web Apps
From the Future
Maxim Salnikov
PWA Developer Advocate
Maxim Salnikov
-
Google Developer Expert in Angular
-
Mobile Meetup Oslo organizer
-
Mobile Era conference organizer
Products from the future
UI Engineer at ForgeRock
Milestones of the web
AJAX
Static
Dynamic
RWD
PWA
Progressive Web App
... Progressive Web App can be seen as an evolving hybrid of regular web pages (or websites) and a mobile application
... a new software development methodology
10 characteristics
- Progressive
- Discoverable
- Linkable
- App-like
- Responsive
- Connectivity-independent
- Re-engageable
- Installable
- Fresh
- Safe
Service Worker API
Push API and Notifications API
Web App Manifest spec
Involved APIs
-
Service Worker API
-
Cache API
-
Fetch API
-
Notifications API
-
Push API
-
IndexedDB API
-
Promises
Today
Fetch
self.addEventListener('fetch', function(event) {
event.respondWith(
...
);
});
App Shell
Networking
Optimization
Session
Management
2-Cookie-Handoff
- Regularly "check in" with the long lived token
- Verify the user's authentication
- Re-issue a new short-lived authentication cookie
Push
self.addEventListener('push', function(event) {
...
event.waitUntil(self.registration.showNotification(title, options));
});
Show
Notification
Background
Action
Background Sync
navigator.serviceWorker.ready.then(function(swRegistration) {
return swRegistration.sync.register('myFirstSync');
});
Defer Data
Sending
Schedule
Downloads
self.addEventListener('sync', function(event) {
if (event.tag == 'myFirstSync') {
event.waitUntil(doSomeStuff());
}
});
Tomorrow
Navigation preload
SW Boot
Navigation request
SW Boot
Navigation request
Navigation preload
self.addEventListener('activate', e => {
e.waitUntil(self.registration.navigationPreload.enable());
});
addEventListener('fetch', event => {
event.respondWith(async function() {
// Respond from the cache if we can
const cachedResponse = await caches.match(event.request);
if (cachedResponse) return cachedResponse;
// Else, use the preloaded response, if it's there
const response = await event.preloadResponse;
if (response) return response;
// Else try the network.
return fetch(event.request);
}());
});
Periodic Sync
-
Restricted by time interval, battery state and network state
-
Would require user permission
-
Don't require any server configuration
-
Allow the user agent to optimize when they fire
Periodic Sync
navigator.serviceWorker.ready.then(function(registration) {
registration.periodicSync.register({
tag: 'get-latest-news', // default: ''
minPeriod: 12 * 60 * 60 * 1000, // default: 0
powerState: 'avoid-draining', // default: 'auto'
networkState: 'avoid-cellular' // default: 'online'
}).then(function(periodicSyncReg) {
// success
}, function() {
// failure
})
});
index.html
Periodic Sync
self.addEventListener('periodicsync', function(event) {
if (event.registration.tag == 'get-latest-news') {
event.waitUntil(fetchAndCacheLatestNews());
}
else {
// unknown sync, may be old, best to unregister
event.registration.unregister();
}
});
service-worker.js
Foreign Fetch
-
API providers with RESTful interfaces
-
Web font providers
-
Analytics providers
-
Image hosting providers
-
Generic content delivery networks
Foreign Fetch
// You can't do this!
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js');
}
Link: </service-worker.js>; rel="serviceworker"; scope="/"
self.addEventListener('install', function(e) {
e.registerForeignFetch({scopes: ['/myscope'], origins: ['*']});
});
index.html
HTTP header
service-worker.js
Foreign Fetch
self.addEventListener('foreignfetch', function(e) {
// Do whatever local work is necessary to handle the fetch,
// or just pass it through to the network:
e.respondWith(fetch(e.request).then(response => ({
response: response,
origin: e.origin,
headers: ['...']
}));
});
service-worker.js
Platforms
Google Android
-
Progressive Web Apps show up in app drawer
-
Open PWA instead of Chrome for the links, registered in this PWA’s scope
-
PWAs can send notifications and ask for permissions
-
PWA is a 1st class citizen on Android
Microsoft Edge
-
Service Worker API, Cache API, Push API come to Windows Insider Program in summer 2017
-
Progressive Web Apps are Hosted Web Apps evolved
-
PWAs could be found and installed via Windows App Store, as well as via regular web search
-
PWA will be a 1st class citizen on Windows 10
Apple Safari
-
Service Worker API in Safari: Under Consideration
-
No PWA support for all browsers in iOS
-
Available for non-Safari browsers on OS X and macOS
-
Safari should not be a blocker
Thank you!
@webmaxru
Maxim Salnikov
Progressive Web Apps New Features
By Maxim Salnikov
Progressive Web Apps New Features
Progressive Web Apps are the next big thing for the web. They combine the advantages of two platforms: searchability and shareability of the web with capabilities and performance of native mobile. As a result, web developers can use their favorite tools to build installable, re-engageable, connectivity independent apps, that can bring native-like performance and user experience.
- 2,963