The document discusses the current state and future of the web. It notes that while native apps have gained popularity, especially on mobile, the web remains strong with over 1 billion active users. It outlines tools from Google like Service Workers that help the web compete with capabilities previously only available to native apps like push notifications, offline access, and background processing. The document advocates for continued progress to simplify the web development process and ensure the longevity of technologies, arguing this will help the web remain diverse and accessible across all platforms.
40. Communications & the web
WebRTC
Desktop:
Microsoft Edge
Google Chrome
Mozilla Firefox
Opera
Android:
Google Chrome
Mozilla Firefox
Opera Mobile
Chrome OS
Firefox OS
60. It's a JavaScript Worker, so it can't access the DOM
directly. Instead responds to postMessages
Service worker is a programmable network proxy
It will be terminated when not in use, and restarted
when it's next needed
Makes extensive use of Promises
Service Workers
64. // The files we want to cache
var urlsToCache = [
'/',
'/styles/main.css',
'/script/main.js'
];
// Set the callback for the install step
self.addEventListener('install', function(event) {
// Perform install steps
});
Installing a Service Worker
65. Inside our install callback:
1. Open a cache
2. Cache our files
3. Confirm whether all the required
assets are cached or not
Installing a Service Worker
69. 1. Update your service worker JavaScript file.
2. Your new service worker will be started and the
install event will be fired.
3. New Service Worker will enter a "waiting" state
4. When open pages are closed, the old Service
Worker will be killed - new service worker will take
control.
5. Once new Service Worker takes control, its
activate event will be fired.
Updating a Service Worker
70. Instant Loading Web Apps with
An Application Shell Architecture
Application Shell
78. // Are Notifications supported in the service worker?
if (!('showNotification' in ServiceWorkerRegistration.prototype)) {
console.warn('Notifications aren't supported.');
return;
}
Push notifications
79. // Check the current Notification permission.
// If its denied, it's a permanent block until the
// user changes the permission
if (Notification.permission === 'denied') {
console.warn('The user has blocked notifications.');
return;
}
Push notifications
80. // Check if push messaging is supported
if (!('PushManager' in window)) {
console.warn('Push messaging isn't supported.');
return;
}
Push notifications
81. // We need the service worker registration to check for a subscription
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
// Do we already have a push message subscription?
serviceWorkerRegistration.pushManager.getSubscription()
.then(function(subscription) {
// Enable any UI which subscribes / unsubscribes from
// push messages.
var pushButton = document.querySelector('.js-push-button');
pushButton.disabled = false;
if (!subscription) {
// We aren't subscribed to push, so set UI
// to allow the user to enable push
return;
}
// Keep your server in sync with the latest subscriptionId
sendSubscriptionToServer(subscription);
// Set your UI to show they have subscribed for
// push messages
pushButton.textContent = 'Disable Push Messages';
isPushEnabled = true;
})
.catch(function(err) {
console.warn('Error during getSubscription()', err);
});
});
Push notifications
85. App Install Banners prerequisites
You have a web app manifest file
You have a service worker registered on
your site. We recommend a simple custom
offline page service worker
Your site is served over HTTPS (you need a
service worker after all)
The user has visited your site twice over
two separate days during the course of two
weeks.
87. Progressive Apps
These apps aren’t packaged and deployed
through stores, they’re just websites that took all
the right vitamins.
They keep the web’s ask-when-you-need-it
permission model and add in new capabilities
like being top-level in your task switcher, on your
home screen, and in your notification tray
- Alex Russell