On Github herschel666 / sw-lightning-talk
var APP_VERSION = 'v-dhth-<version>'; var urlsToCache = [ '/', '/main.js', '…' ];
self.addEventListener('install', function (evnt) { evnt.waitUntil(caches.open(APP_VERSION).then( function (cache) { cache.addAll(urlsToCache); }, console.error) ); });
self.addEventListener('fetch', function (evnt) { evnt.respondWith(caches.match(evnt.request).then(function (response) { return response || fetch(evnt.request); })); });
This all happens in the service-worker.js, which is included like this:
if ( 'serviceWorker' in navigator ) { navigator .serviceWorker .register('/service-worker.js') .then(function () {}, console.error); }
Almost …