|
28 | 28 | <body>
|
29 | 29 | <div id="app">This is your fallback content in case JavaScript fails to load.</div>
|
30 | 30 | <!-- Todo: only include in production -->
|
31 |
| - <script> |
32 |
| - (function() { |
33 |
| - 'use strict'; |
34 |
| - |
35 |
| - // Check to make sure service workers are supported in the current browser, |
36 |
| - // and that the current page is accessed from a secure origin. Using a |
37 |
| - // service worker from an insecure origin will trigger JS console errors. |
38 |
| - const isLocalhost = Boolean(window.location.hostname === 'localhost' || |
39 |
| - // [::1] is the IPv6 localhost address. |
40 |
| - window.location.hostname === '[::1]' || |
41 |
| - // 127.0.0.1/8 is considered localhost for IPv4. |
42 |
| - window.location.hostname.match( |
43 |
| - /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ |
44 |
| - ) |
45 |
| - ); |
46 |
| - |
47 |
| - window.addEventListener('load', function() { |
48 |
| - if ('serviceWorker' in navigator && |
49 |
| - (window.location.protocol === 'https:' || isLocalhost)) { |
50 |
| - navigator.serviceWorker.register('service-worker.js') |
51 |
| - .then(function(registration) { |
52 |
| - // updatefound is fired if service-worker.js changes. |
53 |
| - registration.onupdatefound = function() { |
54 |
| - // updatefound is also fired the very first time the SW is installed, |
55 |
| - // and there's no need to prompt for a reload at that point. |
56 |
| - // So check here to see if the page is already controlled, |
57 |
| - // i.e. whether there's an existing service worker. |
58 |
| - if (navigator.serviceWorker.controller) { |
59 |
| - // The updatefound event implies that registration.installing is set |
60 |
| - const installingWorker = registration.installing; |
61 |
| - |
62 |
| - installingWorker.onstatechange = function() { |
63 |
| - switch (installingWorker.state) { |
64 |
| - case 'installed': |
65 |
| - // At this point, the old content will have been purged and the |
66 |
| - // fresh content will have been added to the cache. |
67 |
| - // It's the perfect time to display a "New content is |
68 |
| - // available; please refresh." message in the page's interface. |
69 |
| - break; |
70 |
| - |
71 |
| - case 'redundant': |
72 |
| - throw new Error('The installing ' + |
73 |
| - 'service worker became redundant.'); |
74 |
| - |
75 |
| - default: |
76 |
| - // Ignore |
77 |
| - } |
78 |
| - }; |
79 |
| - } |
80 |
| - }; |
81 |
| - }).catch(function(e) { |
82 |
| - console.error('Error during service worker registration:', e); |
83 |
| - }); |
84 |
| - } |
85 |
| - }); |
86 |
| - })(); |
87 |
| - </script> |
| 31 | + <%= htmlWebpackPlugin.options.serviceWorkerLoader %> |
88 | 32 | <!-- built files will be auto injected -->
|
89 | 33 | </body>
|
90 | 34 | </html>
|
0 commit comments