sw.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. define(['./workbox-5357ef54'], (function (workbox) { 'use strict';
  68. self.skipWaiting();
  69. workbox.clientsClaim();
  70. /**
  71. * The precacheAndRoute() method efficiently caches and responds to
  72. * requests for URLs in the manifest.
  73. * See https://goo.gl/S9QRab
  74. */
  75. workbox.precacheAndRoute([{
  76. "url": "registerSW.js",
  77. "revision": "3ca0b8505b4bec776b69afdba2768812"
  78. }, {
  79. "url": "index.html",
  80. "revision": "0.5pln1ddsdpg"
  81. }], {});
  82. workbox.cleanupOutdatedCaches();
  83. workbox.registerRoute(
  84. new workbox.NavigationRoute(workbox.createHandlerBoundToURL('index.html'), {
  85. allowlist: [/^\/$/]
  86. })
  87. );
  88. });