Skip to content

Instantly share code, notes, and snippets.

@abdelfattah-atef94
Created November 25, 2019 12:13
Show Gist options
  • Save abdelfattah-atef94/73eb29194fd3a68a0f1389befc33d37c to your computer and use it in GitHub Desktop.
Save abdelfattah-atef94/73eb29194fd3a68a0f1389befc33d37c to your computer and use it in GitHub Desktop.
var cacheName = 'PWA_APP';
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