workbox-navigation-preload.dev.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. this.workbox = this.workbox || {};
  2. this.workbox.navigationPreload = (function (exports, logger_js) {
  3. 'use strict';
  4. try {
  5. self['workbox:navigation-preload:5.1.4'] && _();
  6. } catch (e) {}
  7. /*
  8. Copyright 2018 Google LLC
  9. Use of this source code is governed by an MIT-style
  10. license that can be found in the LICENSE file or at
  11. https://opensource.org/licenses/MIT.
  12. */
  13. /**
  14. * @return {boolean} Whether or not the current browser supports enabling
  15. * navigation preload.
  16. *
  17. * @memberof module:workbox-navigation-preload
  18. */
  19. function isSupported() {
  20. return Boolean(self.registration && self.registration.navigationPreload);
  21. }
  22. /*
  23. Copyright 2018 Google LLC
  24. Use of this source code is governed by an MIT-style
  25. license that can be found in the LICENSE file or at
  26. https://opensource.org/licenses/MIT.
  27. */
  28. /**
  29. * If the browser supports Navigation Preload, then this will disable it.
  30. *
  31. * @memberof module:workbox-navigation-preload
  32. */
  33. function disable() {
  34. if (isSupported()) {
  35. self.addEventListener('activate', event => {
  36. event.waitUntil(self.registration.navigationPreload.disable().then(() => {
  37. {
  38. logger_js.logger.log(`Navigation preload is disabled.`);
  39. }
  40. }));
  41. });
  42. } else {
  43. {
  44. logger_js.logger.log(`Navigation preload is not supported in this browser.`);
  45. }
  46. }
  47. }
  48. /*
  49. Copyright 2018 Google LLC
  50. Use of this source code is governed by an MIT-style
  51. license that can be found in the LICENSE file or at
  52. https://opensource.org/licenses/MIT.
  53. */
  54. /**
  55. * If the browser supports Navigation Preload, then this will enable it.
  56. *
  57. * @param {string} [headerValue] Optionally, allows developers to
  58. * [override](https://developers.google.com/web/updates/2017/02/navigation-preload#changing_the_header)
  59. * the value of the `Service-Worker-Navigation-Preload` header which will be
  60. * sent to the server when making the navigation request.
  61. *
  62. * @memberof module:workbox-navigation-preload
  63. */
  64. function enable(headerValue) {
  65. if (isSupported()) {
  66. self.addEventListener('activate', event => {
  67. event.waitUntil(self.registration.navigationPreload.enable().then(() => {
  68. // Defaults to Service-Worker-Navigation-Preload: true if not set.
  69. if (headerValue) {
  70. self.registration.navigationPreload.setHeaderValue(headerValue);
  71. }
  72. {
  73. logger_js.logger.log(`Navigation preload is enabled.`);
  74. }
  75. }));
  76. });
  77. } else {
  78. {
  79. logger_js.logger.log(`Navigation preload is not supported in this browser.`);
  80. }
  81. }
  82. }
  83. exports.disable = disable;
  84. exports.enable = enable;
  85. exports.isSupported = isSupported;
  86. return exports;
  87. }({}, workbox.core._private));
  88. //# sourceMappingURL=workbox-navigation-preload.dev.js.map