sw.js 4.1 KB

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