If a Web Developer could build Mobile apps�without going through App Store/ Play Store
About speaker
What is PWA?
PWAs are sort of a mix of a mobile app and a web app
PWA App Icon on Homescreen
Chrome uses a set of criteria and visit frequency heuristics to determine when to show the banner. �
Manifest.json
<link rel=”manifest” href=”/manifest.json”>
Push notifications
Once, we have the App icon on the Home screen, let’s try to send some push notification similar to app push notifications.
Service Worker is Javascript Worker and it cannot access the DOM directly. It can communicate with web page through postMessage interface.
Registering a service worker
if ('serviceWorker' in navigator) {� // Register a service worker hosted at the root of the� // site using the default scope.� navigator.serviceWorker.register('/sw.js').then(function(registration) {� console.log('Service worker registration succeeded:', registration);� }).catch(function(error) {� console.log('Service worker registration failed:', error);� });�} else {� console.log('Service workers are not supported.');�}
Steps for push notification
The following summarizes the process of sending and receiving a push message and then displaying a push notification.
On the client:
On the server:
Push notification listener
Push messaging provides a simple and effective way to re-engage with users.
Notification.requestPermission(function(status) {
console.log('Notification permission status:', status);
});
Sending push notifications through server
Voluntary Application Server Identification for Web Push (VAPID) protocol.
Using VAPID
The process is pretty simple:
Web push
const webpush = require('web-push');
// VAPID keys should only be generated only once.
const vapidKeys = webpush.generateVAPIDKeys();
webpush.setGCMAPIKey('<Your GCM API Key Here>');
webpush.setVapidDetails(
'mailto:example@yourdomain.org',
vapidKeys.publicKey,
vapidKeys.privateKey
);
Sending Push notification
const pushSubscription = {
endpoint: '.....',
keys: {
auth: '.....',
p256dh: '.....'
}
};
webpush.sendNotification(pushSubscription, 'Your Push Payload Text');
Offline capabilities
What happens to the app when there is no internet connection?
Update
How to handle the app updates?
New version will not be activated immediately.
It’s up to the developer to display notifications on webapp to inform the user that a new update for the PWA is available
Advantages of React + PWA
React can render in the back-end using React.renderToString() (SSR)
Async import
Tools
Lighthouse�Workbox
Lighthouse
Workbox
Workbox is a collection of libraries and build tools that make it easy to store your website’s file locally, on your users’ devices.
const workbox = new WorkboxSW();
workbox.precache([
{
"url": "/index.html",
"revision": "b3e78d93b20c49d0c927050682c99df3"
}
]);
Workbox caching strategies
const workboxSW = new WorkboxSW();
const networkFirst = workboxSW.strategies.networkFirst();
workboxSW.router.registerRoute('/schedule', networkFirst);