Created
November 25, 2019 12:09
-
-
Save abdelfattah-atef94/54e5635d7c83b4dcf0a5bcd491c7fe4c to your computer and use it in GitHub Desktop.
This file contains 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 = 'hello-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