service-worker.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. console.log('start')
  2. const CASH = 'ver-1'
  3. const urlsToCash = ['index.html', 'offline.html']
  4. const self = this;
  5. self.addEventListener('install', (e) => {
  6. console.log('self wait..')
  7. e.waitUntil(
  8. caches.open(CASH)
  9. .then( cache => {
  10. console.log('open cash', cache)
  11. return cache.addAll(urlsToCash)
  12. })
  13. )
  14. })
  15. self.addEventListener('fetch', () => {
  16. })
  17. self.addEventListener('activate', () => {
  18. })
  19. // /* eslint-disable no-restricted-globals */
  20. // // This service worker can be customized!
  21. // // See https://developers.google.com/web/tools/workbox/modules
  22. // // for the list of available Workbox modules, or add any other
  23. // // code you'd like.
  24. // // You can also remove this file if you'd prefer not to use a
  25. // // service worker, and the Workbox build step will be skipped.
  26. // import { clientsClaim } from 'workbox-core';
  27. // import { ExpirationPlugin } from 'workbox-expiration';
  28. // import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching';
  29. // import { registerRoute } from 'workbox-routing';
  30. // import { StaleWhileRevalidate } from 'workbox-strategies';
  31. // clientsClaim();
  32. // // Precache all of the assets generated by your build process.
  33. // // Their URLs are injected into the manifest variable below.
  34. // // This variable must be present somewhere in your service worker file,
  35. // // even if you decide not to use precaching. See https://cra.link/PWA
  36. // precacheAndRoute(self.__WB_MANIFEST);
  37. // // Set up App Shell-style routing, so that all navigation requests
  38. // // are fulfilled with your index.html shell. Learn more at
  39. // // https://developers.google.com/web/fundamentals/architecture/app-shell
  40. // const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$');
  41. // registerRoute(
  42. // // Return false to exempt requests from being fulfilled by index.html.
  43. // ({ request, url }) => {
  44. // // If this isn't a navigation, skip.
  45. // if (request.mode !== 'navigate') {
  46. // return false;
  47. // } // If this is a URL that starts with /_, skip.
  48. // if (url.pathname.startsWith('/_')) {
  49. // return false;
  50. // } // If this looks like a URL for a resource, because it contains // a file extension, skip.
  51. // if (url.pathname.match(fileExtensionRegexp)) {
  52. // return false;
  53. // } // Return true to signal that we want to use the handler.
  54. // return true;
  55. // },
  56. // createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html')
  57. // );
  58. // // An example runtime caching route for requests that aren't handled by the
  59. // // precache, in this case same-origin .png requests like those from in public/
  60. // registerRoute(
  61. // // Add in any other file extensions or routing criteria as needed.
  62. // ({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
  63. // new StaleWhileRevalidate({
  64. // cacheName: 'images',
  65. // plugins: [
  66. // // Ensure that once this runtime cache reaches a maximum size the
  67. // // least-recently used images are removed.
  68. // new ExpirationPlugin({ maxEntries: 50 }),
  69. // ],
  70. // })
  71. // );
  72. // // This allows the web app to trigger skipWaiting via
  73. // // registration.waiting.postMessage({type: 'SKIP_WAITING'})
  74. // self.addEventListener('message', (event) => {
  75. // if (event.data && event.data.type === 'SKIP_WAITING') {
  76. // self.skipWaiting();
  77. // }
  78. // });
  79. // Any other custom service worker logic can go here.