sw.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 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("/")}}}();
  2. workbox.core.setCacheNameDetails({ prefix: 'MeeChat' })
  3. /**
  4. * The workboxSW.precacheAndRoute() method efficiently caches and responds to
  5. * requests for URLs in the manifest.
  6. * See https://goo.gl/S9QRab
  7. */
  8. self.__precacheManifest = [].concat(self.__precacheManifest || [])
  9. workbox.precaching.suppressWarnings()
  10. workbox.precaching.precacheAndRoute(self.__precacheManifest, {
  11. directoryIndex: null
  12. })
  13. // // const CACHE_NAME = 'mySiteCache';
  14. // // let urlsToCache = [
  15. // // '/',
  16. // // ];
  17. // self.addEventListener('install', function (event) {
  18. // console.log('[ServiceWorker] install')
  19. // // event.waitUntil(
  20. // // caches.open(CACHE_NAME).then(function(caches){
  21. // // console.log('open cache');
  22. // // return caches.addAll(urlsToCache);
  23. // // })
  24. // // )
  25. // })
  26. // self.addEventListener('activate', function (event) {
  27. // console.log('[ServiceWorker] activate')
  28. // // const cacheWhitelist = ['pagesCache', 'blogPostsCache'];
  29. // // event.waitUntil(
  30. // // caches.keys().then(function(cacheNames) {
  31. // // return Promise.all(
  32. // // cacheNames.map(function(cacheName) {
  33. // // if (cacheWhitelist.indexOf(cacheName) === -1) {
  34. // // return caches.delete(cacheName);
  35. // // }
  36. // // })
  37. // // );
  38. // // })
  39. // // );
  40. // })
  41. // self.addEventListener('fetch', function (event) {
  42. // console.log('[ServiceWorker] Fetch', event.request.url)
  43. // })
  44. // self.addEventListener('error', function (event) {
  45. // console.log('[ServiceWorker] error', event)
  46. // })
  47. // self.addEventListener('push', function (event) {
  48. // // console.log('[Service Worker] 收到通知',event);
  49. // console.log(`[Service Worker] 收到的通知数据为: "${event.data.text()}"`)
  50. // function decodeUnicode (str) {
  51. // str = str.replace(/\\/g, '%')
  52. // str = unescape(str)
  53. // str = str.replace(/%/g, '\\')
  54. // str = str.replace(/\\/g, '')
  55. // return str
  56. // }
  57. // let data = JSON.parse(event.data.text())
  58. // const title = decodeUnicode(data.title)
  59. // const options = {
  60. // body: decodeUnicode(data.content),
  61. // icon: 'dice-logo.png'
  62. // }
  63. // event.waitUntil(self.registration.showNotification(title, options))
  64. // })
  65. // // 点击跳转
  66. // self.addEventListener('notificationclick', function (event) {
  67. // event.notification.close()
  68. // // event.waitUntil(
  69. // // clients.openWindow('https://dice.eosget.io/')
  70. // // )
  71. // })