draft PWA
This commit is contained in:
27
snipplets/projects/PWA/serviceWorker.js
Normal file
27
snipplets/projects/PWA/serviceWorker.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const staticExamplePWA = 'example-pwa-site-v1';
|
||||
const assets = [
|
||||
'/',
|
||||
'/index.html',
|
||||
'/styles.css',
|
||||
'/app.js',
|
||||
'/images/Bear.png',
|
||||
'/images/DeusEx.png',
|
||||
'/images/Face.png',
|
||||
'/images/Tony_Stark.jpg',
|
||||
];
|
||||
|
||||
self.addEventListener('install', (installEvent) => {
|
||||
installEvent.waitUntil(
|
||||
caches.open(staticExamplePWA).then((cache) => {
|
||||
cache.addAll(assets);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (fetchEvent) => {
|
||||
fetchEvent.respondWith(
|
||||
caches.match(fetchEvent.request).then((res) => {
|
||||
return res || fetch(fetchEvent.request);
|
||||
}),
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user