Skip to content

Instantly share code, notes, and snippets.

@deanhume
Last active May 3, 2018 07:43
Show Gist options
  • Save deanhume/81960f702ceab4f90725 to your computer and use it in GitHub Desktop.
Save deanhume/81960f702ceab4f90725 to your computer and use it in GitHub Desktop.
A Service Worker that adds an offline page to cache
'use strict';
var cacheVersion = 1;
var currentCache = {
offline: 'offline-cache' + cacheVersion
};
const offlineUrl = 'offline-page.html';
this.addEventListener('install', event => {
event.waitUntil(
caches.open(currentCache.offline).then(function(cache) {
return cache.addAll([
'./img/offline.svg',
offlineUrl
]);
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment