Guest User

Untitled

a guest
Feb 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. "use strict";
  2. var precacheConfig = [
  3. ["/index.html", "1d6f90c196e85efd19bad8422f0b1f65"],
  4. ["/static/css/main.a0cc0ee9.css", "f381e2a4830099f00e91284641ab8cde"],
  5. ["/static/js/main.03430864.js", "0441ebf44bc4da42a41563ecbf727ba6"]
  6. ],
  7. cacheName = "sw-precache-v3-sw-precache-webpack-plugin-" + (self.registration ? self.registration.scope : ""),
  8. ignoreUrlParametersMatching = [/^utm_/],
  9. addDirectoryIndex = function(e, t) {
  10. var n = new URL(e);
  11. return "/" === n.pathname.slice(-1) && (n.pathname += t), n.toString()
  12. },
  13. cleanResponse = function(e) {
  14. return e.redirected ? ("body" in e ? Promise.resolve(e.body) : e.blob()).then(function(t) {
  15. return new Response(t, {
  16. headers: e.headers,
  17. status: e.status,
  18. statusText: e.statusText
  19. })
  20. }) : Promise.resolve(e)
  21. },
  22. createCacheKey = function(e, t, n, r) {
  23. var a = new URL(e);
  24. return r && a.pathname.match(r) || (a.search += (a.search ? "&" : "") + encodeURIComponent(t) + "=" + encodeURIComponent(n)), a.toString()
  25. },
  26. isPathWhitelisted = function(e, t) {
  27. if (0 === e.length) return !0;
  28. var n = new URL(t).pathname;
  29. return e.some(function(e) {
  30. return n.match(e)
  31. })
  32. },
  33. stripIgnoredUrlParameters = function(e, t) {
  34. var n = new URL(e);
  35. return n.hash = "", n.search = n.search.slice(1).split("&").map(function(e) {
  36. return e.split("=")
  37. }).filter(function(e) {
  38. return t.every(function(t) {
  39. return !t.test(e[0])
  40. })
  41. }).map(function(e) {
  42. return e.join("=")
  43. }).join("&"), n.toString()
  44. },
  45. hashParamName = "_sw-precache",
  46. urlsToCacheKeys = new Map(precacheConfig.map(function(e) {
  47. var t = e[0],
  48. n = e[1],
  49. r = new URL(t, self.location),
  50. a = createCacheKey(r, hashParamName, n, /\.\w{8}\./);
  51. return [r.toString(), a]
  52. }));
  53.  
  54. function setOfCachedUrls(e) {
  55. return e.keys().then(function(e) {
  56. return e.map(function(e) {
  57. return e.url
  58. })
  59. }).then(function(e) {
  60. return new Set(e)
  61. })
  62. }
  63. self.addEventListener("install", function(e) {
  64. e.waitUntil(caches.open(cacheName).then(function(e) {
  65. return setOfCachedUrls(e).then(function(t) {
  66. return Promise.all(Array.from(urlsToCacheKeys.values()).map(function(n) {
  67. if (!t.has(n)) {
  68. var r = new Request(n, {
  69. credentials: "same-origin"
  70. });
  71. return fetch(r).then(function(t) {
  72. if (!t.ok) throw new Error("Request for " + n + " returned a response with status " + t.status);
  73. return cleanResponse(t).then(function(t) {
  74. return e.put(n, t)
  75. })
  76. })
  77. }
  78. }))
  79. })
  80. }).then(function() {
  81. return self.skipWaiting()
  82. }))
  83. }), self.addEventListener("activate", function(e) {
  84. var t = new Set(urlsToCacheKeys.values());
  85. e.waitUntil(caches.open(cacheName).then(function(e) {
  86. return e.keys().then(function(n) {
  87. return Promise.all(n.map(function(n) {
  88. if (!t.has(n.url)) return e.delete(n)
  89. }))
  90. })
  91. }).then(function() {
  92. return self.clients.claim()
  93. }))
  94. }), self.addEventListener("fetch", function(e) {
  95. if ("GET" === e.request.method) {
  96. var t, n = stripIgnoredUrlParameters(e.request.url, ignoreUrlParametersMatching),
  97. r = "index.html";
  98. (t = urlsToCacheKeys.has(n)) || (n = addDirectoryIndex(n, r), t = urlsToCacheKeys.has(n));
  99. var a = "/index.html";
  100. !t && "navigate" === e.request.mode && isPathWhitelisted(["^(?!\\/__).*"], e.request.url) && (n = new URL(a, self.location).toString(), t = urlsToCacheKeys.has(n)), t && e.respondWith(caches.open(cacheName).then(function(e) {
  101. return e.match(urlsToCacheKeys.get(n)).then(function(e) {
  102. if (e) return e;
  103. throw Error("The cached response that was expected is missing.")
  104. })
  105. }).catch(function(t) {
  106. return console.warn('Couldn\'t serve response for "%s" from cache: %O', e.request.url, t), fetch(e.request)
  107. }))
  108. }
  109. });
Add Comment
Please, Sign In to add comment