sw.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. let 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 registry[uri] || (
  22. new Promise(resolve => {
  23. if ("document" in self) {
  24. const script = document.createElement("script");
  25. script.src = uri;
  26. script.onload = resolve;
  27. document.head.appendChild(script);
  28. } else {
  29. nextDefineUri = uri;
  30. importScripts(uri);
  31. resolve();
  32. }
  33. })
  34. .then(() => {
  35. let 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 = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
  45. if (registry[uri]) {
  46. // Module is already loading or loaded.
  47. return;
  48. }
  49. let exports = {};
  50. const require = depUri => singleRequire(depUri, uri);
  51. const specialDeps = {
  52. module: { uri },
  53. exports,
  54. require
  55. };
  56. registry[uri] = Promise.all(depsNames.map(
  57. depName => specialDeps[depName] || require(depName)
  58. )).then(deps => {
  59. factory(...deps);
  60. return exports;
  61. });
  62. };
  63. }
  64. <<<<<<< HEAD
  65. define(['./workbox-5357ef54'], function (workbox) {
  66. <<<<<<< HEAD
  67. 'use strict';
  68. =======
  69. ('use strict');
  70. >>>>>>> startLogin
  71. =======
  72. define(['./workbox-5357ef54'], (function (workbox) { 'use strict';
  73. >>>>>>> iteration-work
  74. self.skipWaiting();
  75. workbox.clientsClaim();
  76. /**
  77. * The precacheAndRoute() method efficiently caches and responds to
  78. * requests for URLs in the manifest.
  79. * See https://goo.gl/S9QRab
  80. */
  81. <<<<<<< HEAD
  82. <<<<<<< HEAD
  83. <<<<<<< HEAD
  84. =======
  85. >>>>>>> startLogin
  86. workbox.precacheAndRoute(
  87. [
  88. {
  89. url: 'registerSW.js',
  90. revision: '3ca0b8505b4bec776b69afdba2768812'
  91. },
  92. {
  93. url: 'index.html',
  94. revision: '0.dkdasl3h08'
  95. }
  96. ],
  97. {}
  98. );
  99. <<<<<<< HEAD
  100. =======
  101. =======
  102. >>>>>>> iteration-work
  103. workbox.precacheAndRoute([{
  104. "url": "registerSW.js",
  105. "revision": "3ca0b8505b4bec776b69afdba2768812"
  106. }, {
  107. "url": "index.html",
  108. <<<<<<< HEAD
  109. "revision": "0.lduvfp1t7ko"
  110. }], {});
  111. >>>>>>> iteration-20231220
  112. =======
  113. /**
  114. * https://juejin.cn/post/6844903881189621767
  115. * 缓存策略 有5种
  116. */
  117. >>>>>>> startLogin
  118. workbox.cleanupOutdatedCaches();
  119. workbox.registerRoute(
  120. new workbox.NavigationRoute(workbox.createHandlerBoundToURL('index.html'), {
  121. allowlist: [/^\/$/]
  122. <<<<<<< HEAD
  123. })
  124. =======
  125. }),
  126. workbox.strategies.NetworkFirst()
  127. );
  128. workbox.routing.registerRoute(
  129. new RegExp('.*.html|css|js'),
  130. workbox.strategies.NetworkFirst()
  131. >>>>>>> startLogin
  132. );
  133. });
  134. =======
  135. "revision": "0.mvanbje1bt"
  136. }], {});
  137. workbox.cleanupOutdatedCaches();
  138. workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
  139. allowlist: [/^\/$/]
  140. }));
  141. }));
  142. >>>>>>> iteration-work