Skip to content

Instantly share code, notes, and snippets.

@KevCui
Created December 3, 2017 15:04
Show Gist options
  • Save KevCui/7122d11052f936ef9dc06e7764994e90 to your computer and use it in GitHub Desktop.
Save KevCui/7122d11052f936ef9dc06e7764994e90 to your computer and use it in GitHub Desktop.
Post: Ship PWA Guided by Lighthouse
self.addEventListener('install', e => {
let timeStamp = Date.now();
e.waitUntil(
caches.open('kevin-blog').then(cache => {
return cache.addAll([
`/`,
`/#blog`,
`/css/uno.min.css`,
`/css/font.min.css`,
`/css/resume.min.css`,
`/js/jquery.min.js`,
`/js/main.min.js`,
])
.then(() => self.skipWaiting());
})
)
});
self.addEventListener('activate', event => {
event.waitUntil(self.clients.claim());
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request, {ignoreSearch:true}).then(response => {
return response || fetch(event.request);
})
);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment