sw.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. importScripts("/dist/precache-manifest.1bb23f4e0d41f78beca598051059de98.js");
  2. var workbox=function(){"use strict";try{self.workbox.v["workbox:sw:3.6.3"]=1}catch(t){}const t="https://storage.googleapis.com/workbox-cdn/releases/3.6.3",e={backgroundSync:"background-sync",broadcastUpdate:"broadcast-cache-update",cacheableResponse:"cacheable-response",core:"core",expiration:"cache-expiration",googleAnalytics:"google-analytics",navigationPreload:"navigation-preload",precaching:"precaching",rangeRequests:"range-requests",routing:"routing",strategies:"strategies",streams:"streams"};return new class{constructor(){return this.v={},this.t={debug:"localhost"===self.location.hostname,modulePathPrefix:null,modulePathCb:null},this.e=this.t.debug?"dev":"prod",this.s=!1,new Proxy(this,{get(t,s){if(t[s])return t[s];const o=e[s];return o&&t.loadModule(`workbox-${o}`),t[s]}})}setConfig(t={}){if(this.s)throw new Error("Config must be set before accessing workbox.* modules");Object.assign(this.t,t),this.e=this.t.debug?"dev":"prod"}skipWaiting(){self.addEventListener("install",()=>self.skipWaiting())}clientsClaim(){self.addEventListener("activate",()=>self.clients.claim())}loadModule(t){const e=this.o(t);try{importScripts(e),this.s=!0}catch(s){throw console.error(`Unable to import module '${t}' from '${e}'.`),s}}o(e){if(this.t.modulePathCb)return this.t.modulePathCb(e,this.t.debug);let s=[t];const o=`${e}.${this.e}.js`,r=this.t.modulePathPrefix;return r&&""===(s=r.split("/"))[s.length-1]&&s.splice(s.length-1,1),s.push(o),s.join("/")}}}();
  3. workbox.core.setCacheNameDetails({ prefix: 'MeeChat' })
  4. /**
  5. * The workboxSW.precacheAndRoute() method efficiently caches and responds to
  6. * requests for URLs in the manifest.
  7. * See https://goo.gl/S9QRab
  8. */
  9. self.__precacheManifest = [].concat(self.__precacheManifest || [])
  10. workbox.precaching.suppressWarnings()
  11. workbox.precaching.precacheAndRoute(self.__precacheManifest, {
  12. directoryIndex: null
  13. })
  14. // // const CACHE_NAME = 'mySiteCache';
  15. // // let urlsToCache = [
  16. // // '/',
  17. // // ];
  18. // self.addEventListener('install', function (event) {
  19. // console.log('[ServiceWorker] install')
  20. // // event.waitUntil(
  21. // // caches.open(CACHE_NAME).then(function(caches){
  22. // // console.log('open cache');
  23. // // return caches.addAll(urlsToCache);
  24. // // })
  25. // // )
  26. // })
  27. // self.addEventListener('activate', function (event) {
  28. // console.log('[ServiceWorker] activate')
  29. // // const cacheWhitelist = ['pagesCache', 'blogPostsCache'];
  30. // // event.waitUntil(
  31. // // caches.keys().then(function(cacheNames) {
  32. // // return Promise.all(
  33. // // cacheNames.map(function(cacheName) {
  34. // // if (cacheWhitelist.indexOf(cacheName) === -1) {
  35. // // return caches.delete(cacheName);
  36. // // }
  37. // // })
  38. // // );
  39. // // })
  40. // // );
  41. // })
  42. // self.addEventListener('fetch', function (event) {
  43. // console.log('[ServiceWorker] Fetch', event.request.url)
  44. // })
  45. // self.addEventListener('error', function (event) {
  46. // console.log('[ServiceWorker] error', event)
  47. // })
  48. // self.addEventListener('push', function (event) {
  49. // // console.log('[Service Worker] 收到通知',event);
  50. // console.log(`[Service Worker] 收到的通知数据为: "${event.data.text()}"`)
  51. // function decodeUnicode (str) {
  52. // str = str.replace(/\\/g, '%')
  53. // str = unescape(str)
  54. // str = str.replace(/%/g, '\\')
  55. // str = str.replace(/\\/g, '')
  56. // return str
  57. // }
  58. // let data = JSON.parse(event.data.text())
  59. // const title = decodeUnicode(data.title)
  60. // const options = {
  61. // body: decodeUnicode(data.content),
  62. // icon: 'dice-logo.png'
  63. // }
  64. // event.waitUntil(self.registration.showNotification(title, options))
  65. // })
  66. // // 点击跳转
  67. // self.addEventListener('notificationclick', function (event) {
  68. // event.notification.close()
  69. // // event.waitUntil(
  70. // // clients.openWindow('https://dice.eosget.io/')
  71. // // )
  72. // })