sw.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. define(['./workbox-bb0550c6'], (function (workbox) { 'use strict';
  65. self.skipWaiting();
  66. workbox.clientsClaim();
  67. /**
  68. * The precacheAndRoute() method efficiently caches and responds to
  69. * requests for URLs in the manifest.
  70. * See https://goo.gl/S9QRab
  71. */
  72. workbox.precacheAndRoute([{
  73. "url": "registerSW.js",
  74. "revision": "3ca0b8505b4bec776b69afdba2768812"
  75. }, {
  76. "url": "index.html",
  77. "revision": "0.rmqt4d91upg"
  78. }], {});
  79. workbox.cleanupOutdatedCaches();
  80. workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
  81. allowlist: [/^\/$/]
  82. }));
  83. workbox.registerRoute(({
  84. url
  85. }) => url.origin === "https://dev.kt.colexiu.com", new workbox.NetworkFirst({
  86. "cacheName": "api-cache",
  87. plugins: []
  88. }), 'GET');
  89. }));