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.2KB

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