Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serviceWorker.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. // NOTE: StaticCacheName & FilesToCache list
  3. const staticCacheName = 'omapp-v1.0.0';
  4. const filesToCache = [
  5. '/',
  6. '/index.html',
  7. '/style.css',
  8. '/main.js',
  9. '/favicon.ico',
  10. '/lib/',
  11. '/lib/jquery-3.3.1.min.js',
  12. '/lib/vue.js',
  13. '/lib/vue-router.js'
  14. ];
  15. // NOTE: Registration done in main.js
  16. // NOTE: Install and activate: Populating cache
  17. self.addEventListener('install', function (event) {
  18. console.log('Service worker installing...');
  19. event.waitUntil(
  20. console.log('Trying to install service worker and static cache files.'); caches.open(staticCacheName).then(function (cache) {
  21. return cache.addAll(filesToCache);
  22. })
  23. );
  24. });
  25. // NOTE: Activate structure and delete older cache versions
  26. self.addEventListener('activate', function (event) {
  27. console.log('Activating new service worker...');
  28. const cacheWhitelist = [staticCacheName];
  29. event.waitUntil(
  30. caches.keys().then(function (cacheNames) {
  31. return Promise.all(
  32. cacheNames.map(function (cacheName) {
  33. if (cacheWhitelist.indexOf(cacheName) === -1) {
  34. return caches.delete(cacheName);
  35. }
  36. })
  37. );
  38. })
  39. );
  40. });
  41. // NOTE: Fetch structure // TODO: Setup fetching method
  42. self.addEventListener('fetch', function (event) {
  43. console.log('Fetch event for ', event.request.url);
  44. // Perform some task
  45. });