snapdrop

A Progressive Web App for local file sharing https://github.com/RobinLinus/snapdrop snapdrop.net
git clone http://git.hanabi.in/repos/snapdrop.git
Log | Files | Refs | README | LICENSE

service-worker.js (1312B)


      1 var CACHE_NAME = 'snapdrop-cache-v2';
      2 var urlsToCache = [
      3   'index.html',
      4   './',
      5   'styles.css',
      6   'scripts/network.js',
      7   'scripts/ui.js',
      8   'scripts/clipboard.js',
      9   'scripts/theme.js',
     10   'sounds/blop.mp3',
     11   'images/favicon-96x96.png'
     12 ];
     13 
     14 self.addEventListener('install', function(event) {
     15   // Perform install steps
     16   event.waitUntil(
     17     caches.open(CACHE_NAME)
     18       .then(function(cache) {
     19         console.log('Opened cache');
     20         return cache.addAll(urlsToCache);
     21       })
     22   );
     23 });
     24 
     25 
     26 self.addEventListener('fetch', function(event) {
     27   event.respondWith(
     28     caches.match(event.request)
     29       .then(function(response) {
     30         // Cache hit - return response
     31         if (response) {
     32           return response;
     33         }
     34         return fetch(event.request);
     35       }
     36     )
     37   );
     38 });
     39 
     40 
     41 self.addEventListener('activate', function(event) {
     42   console.log('Updating Service Worker...')
     43   event.waitUntil(
     44     caches.keys().then(function(cacheNames) {
     45       return Promise.all(
     46         cacheNames.filter(function(cacheName) {
     47           // Return true if you want to remove this cache,
     48           // but remember that caches are shared across
     49           // the whole origin
     50           return true
     51         }).map(function(cacheName) {
     52           return caches.delete(cacheName);
     53         })
     54       );
     55     })
     56   );
     57 });