Make Angular App great again
byMeetup #1
Steve Jobs announced new web apps developed in HTML5 and AJAX
* almost everywhere
Works for every user, regardless of browser choice, using progressive enhancement principles.
Fits every device: desktop, mobile, tablet
Allow offline uses or low quality network
Feels like an app to the user
Always up-to-date
Served via HTTPS to prevent snooping and ensure content hasn't been tampered with
Identifiable as an “application” and discoverable by search engines.
Ability to use push notifications. An app keeps in touch with a user.
Provides homescreen icons without the use of an App Store
Can easily be shared via a URL, and does not require complex installation.
Screenshot from GitHub repository PWA-POLICE
+? =
ng add @angular/pwa
serviceWorker: true
in the production configuration.manifest.webmanifest
file and ngsw-config.json
configServiceWorkerModule
for productionindex.html
and adds link to manifest file and meta
tag with theme-color
{
"name": "my-perfect-pwa",
"short_name": "my-perfect-pwa",
"theme_color": "#1976d2",
"background_color": "#fafafa",
"display": "standalone",
"scope": "/",
"start_url": "",
"icons": [
{
"src": "assets/icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "assets/icons/icon-96x96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "assets/icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "assets/icons/icon-144x144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "assets/icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "assets/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "assets/icons/icon-384x384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "assets/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
manifest
and meta tag in the index.html
display
property to one from fullscreen
standalone
, orminimal-ui
,
browser
App is available in the offline mode
$event = fromEvent(window, 'beforeinstallprompt');
$event.subscribe((promptEvent) => {}));
$event = fromEvent(window, 'beforeinstallprompt');
$event.subscribe((event) => {
event.preventDefault();
showCustomPrompt();
));
{
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js"
]
}
}, {
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
]
}
import { SwUpdate } from '@angular/service-worker';
constructor(private swUpdate: SwUpdate) {
swUpdate.available.subscribe(event => {
if (askUserToUpdate()) {
window.location.reload();
}
});
}
self.addEventListener('push', function (event) {
const data = event.data.json();
const title = data.title;
const options = {body: data.body,
icon: 'icons/icon-72x72.png',data: data.click_action};
const promiseChain = self.registration
.showNotification(title, options);
promiseChain.then(function(subscription) {});
event.waitUntil(promiseChain);
});
YES*