sw.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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-74d02f44'], (function (workbox) { 'use strict';
  65. /**
  66. * Welcome to your Workbox-powered service worker!
  67. *
  68. * You'll need to register this file in your web app.
  69. * See https://goo.gl/nhQhGp
  70. *
  71. * The rest of the code is auto-generated. Please don't update this file
  72. * directly; instead, make changes to your Workbox build configuration
  73. * and re-run your build process.
  74. * See https://goo.gl/2aRDsh
  75. */
  76. importScripts("fallback-development.js");
  77. self.skipWaiting();
  78. workbox.clientsClaim();
  79. workbox.registerRoute("/", new workbox.NetworkFirst({
  80. "cacheName": "start-url",
  81. plugins: [{
  82. cacheWillUpdate: async ({
  83. request,
  84. response,
  85. event,
  86. state
  87. }) => {
  88. if (response && response.type === 'opaqueredirect') {
  89. return new Response(response.body, {
  90. status: 200,
  91. statusText: 'OK',
  92. headers: response.headers
  93. });
  94. }
  95. return response;
  96. }
  97. }, {
  98. handlerDidError: async ({
  99. request
  100. }) => self.fallback(request)
  101. }]
  102. }), 'GET');
  103. workbox.registerRoute(/.*/i, new workbox.NetworkOnly({
  104. "cacheName": "dev",
  105. plugins: [{
  106. handlerDidError: async ({
  107. request
  108. }) => self.fallback(request)
  109. }]
  110. }), 'GET');
  111. }));
  112. //# sourceMappingURL=sw.js.map