PWA Fundvelo der Caritas.
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.

service-worker.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // In development, always fetch from the network and do not enable offline support.
  2. // This is because caching would make development more difficult (changes would not
  3. // be reflected on the first load after each change).
  4. const staticCacheName = 'site-static-v-0-2-0'; // IMPORTANT: CHANGE THE VERSION IN THIS NAME EVERY TIME THE APP IS DEPLOYED ON SERVER WITH CHANGES!!!
  5. const appsettings_url = 'appsettings.json';
  6. const assets = [
  7. './',
  8. '/index.html',
  9. '/account',
  10. '/account/Found',
  11. '/account/Missing',
  12. '/info',
  13. '/caritas_services',
  14. '/lost_found',
  15. '/keydata',
  16. '/keydata/Found',
  17. '/keydata/Missing',
  18. '/conclusion_found',
  19. '/conclusion_missing',
  20. '/doneimage',
  21. '/failureimage',
  22. 'favicon.ico',
  23. 'images/batch_found.png',
  24. 'images/batch_fundvelo.png',
  25. 'images/batch_kulturlegi.png',
  26. 'images/batch_markt.png',
  27. 'images/batch_missing.png',
  28. 'images/caritas_logo.png',
  29. 'images/integrate_logo.png',
  30. 'images/done.png',
  31. 'images/icon_camera.png',
  32. 'images/icon_driveupload.png',
  33. 'images/icon_location.png',
  34. 'icons/icon-144.png',
  35. 'css/app.css',
  36. 'css/united/bootstrap.min.css',
  37. 'css/united/_bootswatch.min.css',
  38. 'css/united/_variables.min.css',
  39. '_content/matblazor/dist/matblazor.css',
  40. '_content/matblazor/dist/matblazor.js',
  41. '_content/blazoranimate/blazoranimateinterop.js',
  42. '_content/blazoranimate/aos.css',
  43. '_framework/blazor.webassembly.js',
  44. '_framework/blazor.boot.json',
  45. '_framework/dotnet.5.0.8.js',
  46. 'https://fonts.googleapis.com/css?family=Roboto:300,400,500',
  47. 'https://fonts.googleapis.com/icon?family=Material+Icons',
  48. 'https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap',
  49. 'https://fonts.gstatic.com/s/ubuntu/v15/4iCs6KVjbNBYlgoKfw72nU6AFw.woff2',
  50. 'https://fonts.gstatic.com/s/roboto/v27/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2',
  51. 'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2',
  52. 'https://fonts.gstatic.com/s/materialicons/v85/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2',
  53. 'appsettings.json',
  54. 'manifest.json'
  55. ];
  56. // install event
  57. self.addEventListener('install', event => {
  58. event.waitUntil(
  59. caches.open(staticCacheName).then(cache => {
  60. console.log('caching app assets');
  61. cache.addAll(assets);
  62. })
  63. );
  64. });
  65. // activate event
  66. self.addEventListener('activate', event => {
  67. //delete any caches that aren't in expectedCaches
  68. //which will get rid of site-static-v<n-1>
  69. event.waitUntil(
  70. caches.keys().then(keys => Promise.all(
  71. keys.map(key => {
  72. if (!staticCacheName.includes(key)) {
  73. return caches.delete(key);
  74. }
  75. })
  76. )).then(() => {
  77. console.log('Now ready to handle fetches!');
  78. })
  79. );
  80. });
  81. // fetch events (appsettings are always first fetched from network)
  82. self.addEventListener('fetch', event => {
  83. if (event.request.url.endsWith(appsettings_url)) {
  84. fetch(event.request).then(function (response) {
  85. return caches.open(staticCacheName).then(function (cache) {
  86. console.log('update cache');
  87. cache.put(event.request, response.clone());
  88. return response;
  89. });
  90. }).catch(function () {
  91. var cr;
  92. console.log('catch network fetch failure 1');
  93. event.waitUntil(
  94. caches.match(event.request).then(cacheRes => {
  95. console.log('catch network fetch failure 2');
  96. console.log(cacheRes);
  97. cr = cacheRes;
  98. })
  99. );
  100. console.log('catch network fetch failure 3');
  101. console.log(cr);
  102. return cr;
  103. //fromCache(event.request);
  104. })
  105. } else {
  106. event.respondWith(
  107. caches.match(event.request).then(cacheRes => {
  108. return cacheRes || fetch(event.request);
  109. })
  110. );
  111. }
  112. });
  113. //self.addEventListener('fetch', event => {
  114. // if (event.request.url.endsWith(appsettings_url)) {
  115. // networkOrCache(event.request);
  116. // } else {
  117. // event.respondWith(
  118. // caches.match(event.request).then(cacheRes => {
  119. // return cacheRes || fetch(event.request);
  120. // })
  121. // );
  122. // }
  123. //});
  124. //function networkOrCache(request) {
  125. // return fetch(request).then(function (response) {
  126. // caches.open(staticCacheName).then(function (cache) {
  127. // console.log('update cache');
  128. // cache.put(request, response.clone());
  129. // });
  130. // return response.ok ? response : fromCache(request);
  131. // //}).catch(function () {
  132. // // return fromCache(request);
  133. // });
  134. //}
  135. //function fromCache(request) {
  136. // return caches.open(staticCacheName).then(function (cache) {
  137. // return cache.match(request).then(function (matching) {
  138. // return matching || Promise.reject('request-not-in-cache');
  139. // });
  140. // });
  141. //}