sw.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Copyright 2018 Google Inc. All Rights Reserved.
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. // If the loader is already loaded, just stop.
  14. if (!self.define) {
  15. const registry = {};
  16. // Used for `eval` and `importScripts` where we can't get script URL by other means.
  17. // In both cases, it's safe to use a global var because those functions are synchronous.
  18. let nextDefineUri;
  19. const singleRequire = (uri, parentUri) => {
  20. uri = new URL(uri + '.js', parentUri).href;
  21. return (
  22. registry[uri] ||
  23. new Promise(resolve => {
  24. if ('document' in self) {
  25. const script = document.createElement('script');
  26. script.src = uri;
  27. script.onload = resolve;
  28. document.head.appendChild(script);
  29. } else {
  30. nextDefineUri = uri;
  31. importScripts(uri);
  32. resolve();
  33. }
  34. }).then(() => {
  35. const promise = registry[uri];
  36. if (!promise) {
  37. throw new Error(`Module ${uri} didn’t register its module`);
  38. }
  39. return promise;
  40. })
  41. );
  42. };
  43. self.define = (depsNames, factory) => {
  44. const uri =
  45. nextDefineUri ||
  46. ('document' in self ? document.currentScript.src : '') ||
  47. location.href;
  48. if (registry[uri]) {
  49. // Module is already loading or loaded.
  50. return;
  51. }
  52. const exports = {};
  53. const require = depUri => singleRequire(depUri, uri);
  54. const specialDeps = {
  55. module: { uri },
  56. exports,
  57. require
  58. };
  59. registry[uri] = Promise.all(
  60. depsNames.map(depName => specialDeps[depName] || require(depName))
  61. ).then(deps => {
  62. factory(...deps);
  63. return exports;
  64. });
  65. };
  66. }
  67. <<<<<<< HEAD
  68. <<<<<<< HEAD
  69. define(['./workbox-5357ef54'], function (workbox) {
  70. ('use strict');
  71. =======
  72. define(['./workbox-bb0550c6'], (function (workbox) { 'use strict';
  73. >>>>>>> iteration-20240723
  74. =======
  75. define(['./workbox-88bf3160'], (function (workbox) { 'use strict';
  76. >>>>>>> iteration-20240909
  77. self.skipWaiting();
  78. workbox.clientsClaim();
  79. /**
  80. * The precacheAndRoute() method efficiently caches and responds to
  81. * requests for URLs in the manifest.
  82. * See https://goo.gl/S9QRab
  83. */
  84. <<<<<<< HEAD
  85. <<<<<<< HEAD
  86. workbox.precacheAndRoute(
  87. [
  88. {
  89. url: 'registerSW.js',
  90. revision: '3ca0b8505b4bec776b69afdba2768812'
  91. },
  92. {
  93. url: 'index.html',
  94. revision: '0.3vo3lspd3m'
  95. }
  96. ],
  97. {}
  98. );
  99. /**
  100. * https://juejin.cn/post/6844903881189621767
  101. * 缓存策略 有5种
  102. */
  103. workbox.cleanupOutdatedCaches();
  104. workbox.registerRoute(
  105. new workbox.NavigationRoute(workbox.createHandlerBoundToURL('index.html'), {
  106. allowlist: [/^\/$/]
  107. }),
  108. workbox.strategies.networkOnly()
  109. );
  110. workbox.routing.registerRoute(
  111. new RegExp('.*.html|css'),
  112. workbox.strategies.networkFirst()
  113. );
  114. workbox.routing.registerRoute(
  115. new RegExp('|js'),
  116. workbox.strategies.networkOnly()
  117. );
  118. });
  119. =======
  120. =======
  121. >>>>>>> iteration-20240909
  122. workbox.precacheAndRoute([{
  123. "url": "registerSW.js",
  124. "revision": "3ca0b8505b4bec776b69afdba2768812"
  125. }, {
  126. "url": "index.html",
  127. <<<<<<< HEAD
  128. "revision": "0.oe0btcmloh8"
  129. =======
  130. "revision": "0.l07eibm7mu"
  131. >>>>>>> iteration-20240909
  132. }], {});
  133. workbox.cleanupOutdatedCaches();
  134. workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
  135. allowlist: [/^\/$/]
  136. }));
  137. workbox.registerRoute(({
  138. url
  139. }) => url.origin === "https://dev.kt.colexiu.com", new workbox.NetworkFirst({
  140. "cacheName": "api-cache",
  141. plugins: []
  142. }), 'GET');
  143. }));
  144. <<<<<<< HEAD
  145. >>>>>>> iteration-20240723
  146. =======
  147. >>>>>>> iteration-20240909