Skip to content

Instantly share code, notes, and snippets.

@abdelfattah-atef94
Created November 25, 2019 12:09
Show Gist options
  • Save abdelfattah-atef94/54e5635d7c83b4dcf0a5bcd491c7fe4c to your computer and use it in GitHub Desktop.
Save abdelfattah-atef94/54e5635d7c83b4dcf0a5bcd491c7fe4c to your computer and use it in GitHub Desktop.
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