|
30 | 30 | <link rel="manifest" href="manifest.json"> |
31 | 31 | </head> |
32 | 32 | <body> |
33 | | - <!-- This script installs service_worker.js to provide PWA functionality to |
34 | | - application. For more information, see: |
35 | | - https://developers.google.com/web/fundamentals/primers/service-workers --> |
36 | | - <script> |
37 | | - var serviceWorkerVersion = null; |
38 | | - var scriptLoaded = false; |
39 | | - function loadMainDartJs() { |
40 | | - if (scriptLoaded) { |
41 | | - return; |
42 | | - } |
43 | | - scriptLoaded = true; |
44 | | - var scriptTag = document.createElement('script'); |
45 | | - scriptTag.src = 'main.dart.js'; |
46 | | - scriptTag.type = 'application/javascript'; |
47 | | - document.body.append(scriptTag); |
48 | | - } |
49 | | - |
50 | | - if ('serviceWorker' in navigator) { |
51 | | - // Service workers are supported. Use them. |
52 | | - window.addEventListener('load', function () { |
53 | | - // Wait for registration to finish before dropping the <script> tag. |
54 | | - // Otherwise, the browser will load the script multiple times, |
55 | | - // potentially different versions. |
56 | | - var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion; |
57 | | - navigator.serviceWorker.register(serviceWorkerUrl) |
58 | | - .then((reg) => { |
59 | | - function waitForActivation(serviceWorker) { |
60 | | - serviceWorker.addEventListener('statechange', () => { |
61 | | - if (serviceWorker.state == 'activated') { |
62 | | - console.log('Installed new service worker.'); |
63 | | - loadMainDartJs(); |
64 | | - } |
65 | | - }); |
66 | | - } |
67 | | - if (!reg.active && (reg.installing || reg.waiting)) { |
68 | | - // No active web worker and we have installed or are installing |
69 | | - // one for the first time. Simply wait for it to activate. |
70 | | - waitForActivation(reg.installing ?? reg.waiting); |
71 | | - } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) { |
72 | | - // When the app updates the serviceWorkerVersion changes, so we |
73 | | - // need to ask the service worker to update. |
74 | | - console.log('New service worker available.'); |
75 | | - reg.update(); |
76 | | - waitForActivation(reg.installing); |
77 | | - } else { |
78 | | - // Existing service worker is still good. |
79 | | - console.log('Loading app from service worker.'); |
80 | | - loadMainDartJs(); |
81 | | - } |
82 | | - }); |
83 | | - |
84 | | - // If service worker doesn't succeed in a reasonable amount of time, |
85 | | - // fallback to plaint <script> tag. |
86 | | - setTimeout(() => { |
87 | | - if (!scriptLoaded) { |
88 | | - console.warn( |
89 | | - 'Failed to load app from service worker. Falling back to plain <script> tag.', |
90 | | - ); |
91 | | - loadMainDartJs(); |
92 | | - } |
93 | | - }, 4000); |
94 | | - }); |
95 | | - } else { |
96 | | - // Service workers not supported. Just drop the <script> tag. |
97 | | - loadMainDartJs(); |
98 | | - } |
99 | | - </script> |
| 33 | + <script src="flutter_bootstrap.js" async></script> |
100 | 34 | </body> |
101 | 35 | </html> |
0 commit comments