by Gion Kunz
caniuse, July 2020, global 1%
* In some browsers ;-)
navigator.serviceWorker
.register('/sw.js', { scope: '/sw-example/' })
.then(reg => {
// Registration succeeded
}).catch(error => {
// Error
});
// Install phase
self.addEventListener('install', event => {
event.waitUntil(
caches.open('v1').then(cache => {
return cache.addAll([
'/sw-examples/',
'/sw-examples/index.html',
'/sw-examples/style.css',
'/sw-examples/app.js'
]);
})
);
});
// Fetch interception proxy, try cache, load and cache on miss
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
return response ||
fetch(event.request).then(response => {
caches.open('v1').then(cache =>
cache.put(event.request, response.clone());
);
return response;
});
}));
});
caniuse, August 2018
{
"name": "HackerWeb",
"short_name": "HackerWeb",
"start_url": ".",
"display": "standalone",
"background_color" : "#fff" ,
"description": "Simple HackerNews Web App.",
"Icons": [{
"src": "images/touch/homescreen48.png",
"sizes": "48x48",
"type": "image/png"
}
.....
caniuse, July 2020, gloabl 1%
caniuse, July 2020, gloabl 1%
npm install -g @angular/cli
ng new example-pwa
cd example-pwa
ng add @angular/pwa
@NgModule ({
bootstrap: [AppComponent],
imports: [
RouterModule.forRoot(ROUTES, {
preloadingStrategy: PreloadAllModules
})
]
})
class MainModule {}