Skip to content

Commit 454392d

Browse files
committed
chore: update the way to bootstrap web example (recommended by flutter)
1 parent 86344bf commit 454392d

File tree

1 file changed

+1
-65
lines changed

1 file changed

+1
-65
lines changed

example/web/index.html

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

0 commit comments

Comments
 (0)