sw-template.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. /*
  3. Copyright 2018 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. // All workbox references must come after the workboxSWImport/importScripts block
  9. module.exports = `/**
  10. * Welcome to your Workbox-powered service worker!
  11. *
  12. * You'll need to register this file in your web app and you should
  13. * disable HTTP caching for this file too.
  14. * See https://goo.gl/nhQhGp
  15. *
  16. * The rest of the code is auto-generated. Please don't update this file
  17. * directly; instead, make changes to your Workbox build configuration
  18. * and re-run your build process.
  19. * See https://goo.gl/2aRDsh
  20. */
  21. <% if (workboxSWImport) { %>
  22. importScripts(<%= JSON.stringify(workboxSWImport) %>);
  23. <% if (modulePathPrefix) { %>workbox.setConfig({modulePathPrefix: <%= JSON.stringify(modulePathPrefix) %>});<% } %>
  24. <% } %>
  25. <% if (importScripts) { %>
  26. importScripts(
  27. <%= importScripts.map(JSON.stringify).join(',\\n ') %>
  28. );
  29. <% } %>
  30. <% if (navigationPreload) { %>workbox.navigationPreload.enable();<% } %>
  31. <% if (cacheId) { %>workbox.core.setCacheNameDetails({prefix: <%= JSON.stringify(cacheId) %>});<% } %>
  32. <% if (skipWaiting) { %>
  33. workbox.core.skipWaiting();
  34. <% } else { %>
  35. self.addEventListener('message', (event) => {
  36. if (event.data && event.data.type === 'SKIP_WAITING') {
  37. self.skipWaiting();
  38. }
  39. });
  40. <% } %>
  41. <% if (clientsClaim) { %>workbox.core.clientsClaim();<% } %>
  42. <% if (Array.isArray(manifestEntries)) {%>
  43. /**
  44. * The workboxSW.precacheAndRoute() method efficiently caches and responds to
  45. * requests for URLs in the manifest.
  46. * See https://goo.gl/S9QRab
  47. */
  48. self.__precacheManifest = <%= JSON.stringify(manifestEntries, null, 2) %>.concat(self.__precacheManifest || []);
  49. workbox.precaching.precacheAndRoute(self.__precacheManifest, <%= precacheOptionsString %>);
  50. <% } else { %>
  51. if (Array.isArray(self.__precacheManifest)) {
  52. workbox.precaching.precacheAndRoute(self.__precacheManifest, <%= precacheOptionsString %>);
  53. }
  54. <% } %>
  55. <% if (cleanupOutdatedCaches) { %>workbox.precaching.cleanupOutdatedCaches();<% } %>
  56. <% if (navigateFallback) { %>workbox.routing.registerNavigationRoute(workbox.precaching.getCacheKeyForURL(<%= JSON.stringify(navigateFallback) %>)<% if (navigateFallbackWhitelist || navigateFallbackBlacklist) { %>, {
  57. <% if (navigateFallbackWhitelist) { %>whitelist: [<%= navigateFallbackWhitelist %>],<% } %>
  58. <% if (navigateFallbackBlacklist) { %>blacklist: [<%= navigateFallbackBlacklist %>],<% } %>
  59. }<% } %>);<% } %>
  60. <% if (runtimeCaching) { runtimeCaching.forEach(runtimeCachingString => {%><%= runtimeCachingString %><% });} %>
  61. <% if (offlineAnalyticsConfigString) { %>workbox.googleAnalytics.initialize(<%= offlineAnalyticsConfigString %>);<% } %>`;