Skip to content

Instantly share code, notes, and snippets.

@kimuradev
Created July 28, 2019 02:29
Show Gist options
  • Save kimuradev/d581472645bab1873c44b9aeec0b707d to your computer and use it in GitHub Desktop.
Save kimuradev/d581472645bab1873c44b9aeec0b707d to your computer and use it in GitHub Desktop.
PWA Medium
var cacheName = 'vanilla-pwa';
var filesToCache = ['/', '/index.html', '/css/style.css', '/js/main.js'];
/* Start the service worker and cache all of the app's content */
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll(filesToCache);
})
);
});
/* Serve cached content when offline */
self.addEventListener('fetch', function(e) {
e.respondWith(
caches.match(e.request).then(function(response) {
return response || fetch(e.request);
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment