Created
July 28, 2019 02:29
-
-
Save kimuradev/d581472645bab1873c44b9aeec0b707d to your computer and use it in GitHub Desktop.
PWA Medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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