-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsw.min.js.map
1 lines (1 loc) · 4.5 KB
/
sw.min.js.map
1
{"version":3,"sources":["sw.js"],"names":["cacheName","indexPage","offlinePages","updateStaticCache","caches","open","then","cache","addAll","clearOldCaches","keys","Promise","filter","key","map","isCachableResponse","request","response","indexOf","self","addEventListener","event","waitUntil","skipWaiting","method","navigator","onLine","isHtmlRequest","respondWith","console","fetch","clonedResponse","mode","match","redirect","put"],"mappings":"AAMA,IAAIA,UAAY,oCAEZC,UAAY,aACZC,aAAe,CAACD,WAEpB,SAASE,oBACR,OAAAC,OAAaC,KAANL,WAAAM,KAAA,SAA4BC,GAElC,OAAAA,EAAOA,OAAMC,gBAIf,SAASC,iBACR,OAAAL,OAAaM,OAANJ,KAAA,SAAmBI,GACzB,OAAAC,QAAOA,IACLD,EADiBE,OAEX,SAAUC,GAChB,OAAA,IAAAA,EAAOT,QAAMJ,aAJhBc,IAAA,SAAAD,GAOA,OAAAT,OAAA,OAAAS,QAMD,SAASE,cAAAA,GACR,OAAA,IAAAC,EAAQC,QAAYA,IAAAA,UAApBC,QAAA,aAGDC,SAAKC,mBAAiBH,GACrBI,OAAMC,GAAUnB,EAAAA,GAGhBgB,KAJDC,iBAAA,UAAA,SAAAC,GAMAF,EAAKC,UACJC,oBAAgBZ,KAAAA,WACd,OAAAU,KAAWI,mBAMbJ,KAAAC,iBAAoBJ,WAApB,SAAAK,eAEAZ,iBAAYe,KAAR,WACH,OAAKC,KAAAA,QAAUC,aAGfP,KAAAC,iBAAA,QAAA,SAAAC,GACA,IAAAL,EAAAK,EAAAL,QAED,GAAkBA,QAAlBA,EAAIW,OAEHN,OAAAA,UAAMO,QAAiBD,cAALX,GACZD,EAAAA,YAAkBX,OAACa,MAAWhB,iBAGhC4B,EAGD,GAAAF,cAAAX,iBACDc,MAAAd,GARgBV,KAAA,SASPW,GACT,GAAAF,mBAAoBC,GAAb,CACN,IAAAe,EAAiBf,EAAQgB,QACxB5B,OAAAC,KAAOD,WAAAE,KAAaL,SAApBM,uBAdL,OAmBOU,IAGL,MAAA,WACA,OAAAb,OAAA6B,MAAAjB,GAAAV,KAAA,SAAAW,gCAKEiB,EAHGN,OAANK,MAAkB7B,oBAOdA,CACCyB,GACaM,mBAAbd,EAAAL,QAAAT,OAFD,gBAGCc,EAAAL,QAHDgB,YAOFX,EAdFO,YAeAxB,OAAA6B,MAAAjB,GAAAV,KAAA,SAAAW,GAnDF","file":"sw.min.js","sourcesContent":["/*global caches, self, Promise, */\n/*!\n * https://github.com/meanbee/magento-meanbee-pwa/issues/20#issuecomment-497626347\n * This is a reworked code of the \"Offline copy of pages\" service worker\n */\n\nvar cacheName = \"shimansky.biz-offline-v1602190201\";\n\nvar indexPage = \"index.html\";\nvar offlinePages = [indexPage];\n\nfunction updateStaticCache() {\n\treturn caches.open(cacheName).then(function (cache) {\n\t\tconsole.log(\"[sw.js] Added to offline during install: \" + offlinePages);\n\t\treturn cache.addAll(offlinePages);\n\t});\n}\n\nfunction clearOldCaches() {\n\treturn caches.keys().then(function (keys) {\n\t\treturn Promise.all(keys.filter(function (key) {\n\t\t\t\treturn key.indexOf(cacheName) !== 0;\n\t\t\t}).map(function (key) {\n\t\t\t\treturn caches.delete (key);\n\t\t\t}));\n\t});\n}\n\nfunction isHtmlRequest(request) {\n\treturn request.headers.get(\"Accept\").indexOf(\"text/html\") !== -1;\n}\n\nfunction isCachableResponse(response) {\n\treturn (response && response.ok);\n}\n\nself.addEventListener(\"install\", function (event) {\n\tevent.waitUntil(updateStaticCache().then(function () {\n\t\t\treturn self.skipWaiting();\n\t\t}));\n});\n\nself.addEventListener(\"activate\", function (event) {\n\tevent.waitUntil(clearOldCaches().then(function () {\n\t\t\treturn self.clients.claim();\n\t\t}));\n});\n\nself.addEventListener(\"fetch\", function (event) {\n\n\tvar request = event.request;\n\n\tif (request.method !== \"GET\") {\n\t\tif (!navigator.onLine && isHtmlRequest(request)) {\n\t\t\treturn event.respondWith(caches.match(indexPage));\n\t\t}\n\t\treturn;\n\t}\n\n\tif (isHtmlRequest(request)) {\n\n\t\tevent.respondWith(fetch(request).then(function (response) {\n\t\t\t\tif (isCachableResponse(response)) {\n\t\t\t\t\tvar clonedResponse = response.clone();\n\t\t\t\t\tcaches.open(cacheName).then(function (cache) {\n\t\t\t\t\t\tconsole.log(\"[sw.js] Added to offline: \" + clonedResponse.url);\n\t\t\t\t\t\treturn cache.put(request, clonedResponse);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn response;\n\t\t\t}).catch (function () {\n\t\t\t\treturn caches.match(request).then(function (response) {\n\t\t\t\t\tif (!response && request.mode == \"navigate\") {\n\t\t\t\t\t\treturn caches.match(indexPage);\n\t\t\t\t\t}\n\t\t\t\t\treturn response;\n\t\t\t\t});\n\t\t\t}));\n\t} else {\n\n\t\tif (event.request.cache === \"only-if-cached\" && event.request.mode !== \"same-origin\") {\n\t\t\treturn;\n\t\t}\n\n\t\tevent.respondWith(caches.match(request).then(function (response) {\n\t\t\t\treturn response || fetch(request, {\n\t\t\t\t\tcredentials: \"include\",\n\t\t\t\t\tredirect: \"follow\"\n\t\t\t\t}).then(function (response) {\n\t\t\t\t\tif (isCachableResponse(response)) {\n\t\t\t\t\t\tvar clonedResponse = response.clone();\n\t\t\t\t\t\tcaches.open(cacheName).then(function (cache) {\n\t\t\t\t\t\t\tconsole.log(\"[sw.js] Added to offline: \" + clonedResponse.url);\n\t\t\t\t\t\t\treturn cache.put(request, clonedResponse);\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn response;\n\t\t\t\t});\n\t\t\t}));\n\t}\n});\n"]}