PWA Fundvelo der Caritas.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

service-worker.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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-9-14'; // 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. '/pending_overview',
  21. '/history_found',
  22. '/history_missing',
  23. '/doneimage',
  24. '/failureimage',
  25. '/warningimage',
  26. '/favicon.ico',
  27. 'images/batch_found.png',
  28. 'images/batch_fundvelo.png',
  29. 'images/batch_kulturlegi.png',
  30. 'images/batch_markt.png',
  31. 'images/batch_missing.png',
  32. 'images/batch_pending.png',
  33. 'images/caritas_logo.png',
  34. 'images/integrate_logo.png',
  35. 'images/done.png',
  36. 'images/failure.png',
  37. 'images/warning.png',
  38. 'images/icon_camera.png',
  39. 'images/icon_driveupload.png',
  40. 'images/icon_location.png',
  41. 'icons/icon-144.png',
  42. 'css/app.css',
  43. 'css/united/bootstrap.min.css',
  44. 'css/united/_bootswatch.min.css',
  45. 'css/united/_variables.min.css',
  46. '_content/matblazor/dist/matblazor.css',
  47. '_content/matblazor/dist/matblazor.js',
  48. '_content/blazoranimate/blazoranimateinterop.js',
  49. '_content/blazoranimate/aos.css',
  50. '_content/TG.Blazor.IndexedDB/indexedDb.Blazor.js',
  51. '_framework/blazor.webassembly.js',
  52. '_framework/blazor.boot.json',
  53. '_framework/dotnet.5.0.9.js',
  54. 'https://fonts.googleapis.com/css?family=Roboto:300,400,500',
  55. 'https://fonts.googleapis.com/icon?family=Material+Icons',
  56. 'https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap',
  57. 'https://fonts.gstatic.com/s/ubuntu/v15/4iCs6KVjbNBYlgoKfw72nU6AFw.woff2',
  58. 'https://fonts.gstatic.com/s/roboto/v27/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2',
  59. 'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2',
  60. 'https://fonts.gstatic.com/s/materialicons/v85/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2',
  61. 'https://fonts.gstatic.com/s/ubuntu/v15/4iCv6KVjbNBYlgoCxCvjsGyNPYZvgw.woff2',
  62. 'appsettings.json',
  63. 'manifest.json'
  64. ];
  65. // install event
  66. self.addEventListener('install', event => {
  67. event.waitUntil(
  68. caches.open(staticCacheName).then(cache => {
  69. console.log('caching app assets');
  70. cache.addAll(assets);
  71. })
  72. )
  73. });
  74. // activate event
  75. self.addEventListener('activate', event => {
  76. //delete any caches that aren't in expectedCaches
  77. //which will get rid of site-static-v<old-version>
  78. event.waitUntil(
  79. caches.keys().then(keys => Promise.all(
  80. keys.map(key => {
  81. if (!staticCacheName.includes(key)) {
  82. return caches.delete(key);
  83. }
  84. })
  85. )).then(() => {
  86. console.log('Now ready to handle fetches!');
  87. })
  88. );
  89. self.clients.claim();
  90. });
  91. // fetch events (Network first strategy, cache update after fetch)
  92. self.addEventListener('fetch', function (event) {
  93. event.respondWith(fromNetwork(event.request, 30000).catch(function () {
  94. return fromCache(event.request);
  95. }));
  96. });
  97. function fromNetwork(request, timeout) {
  98. return new Promise(function (fulfill, reject) {
  99. var timeoutId = setTimeout(reject, timeout);
  100. fetch(request).then(function (response) {
  101. clearTimeout(timeoutId);
  102. var responseClone = response.clone();
  103. caches.open(staticCacheName).then(function (cache) {
  104. if (request.method != 'POST') // post can't be cached, causes an exception
  105. cache.put(request, responseClone);
  106. });
  107. fulfill(response);
  108. }, reject);
  109. });
  110. }
  111. function fromCache(request) {
  112. return caches.open(staticCacheName).then(function (cache) {
  113. return cache.match(request).then(function (matching) {
  114. return matching || Promise.reject('no-match');
  115. });
  116. });
  117. }
  118. self.addEventListener('message', function (event) {
  119. if (event.data.action === 'skipWaiting') {
  120. self.skipWaiting();
  121. }
  122. });