index.html 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!--
  5. If you are serving your web app in a path other than the root, change the
  6. href value below to reflect the base path you are serving from.
  7. The path provided below has to start and end with a slash "/" in order for
  8. it to work correctly.
  9. For more details:
  10. * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  11. -->
  12. <base href="/">
  13. <meta charset="UTF-8">
  14. <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  15. <meta name="description" content="A new Flutter project.">
  16. <!-- iOS meta tags & icons -->
  17. <meta name="apple-mobile-web-app-capable" content="yes">
  18. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  19. <meta name="apple-mobile-web-app-title" content="gobang">
  20. <link rel="apple-touch-icon" href="icons/Icon-192.png">
  21. <title>gobang</title>
  22. <link rel="manifest" href="manifest.json">
  23. </head>
  24. <body>
  25. <!-- This script installs service_worker.js to provide PWA functionality to
  26. application. For more information, see:
  27. https://developers.google.com/web/fundamentals/primers/service-workers -->
  28. <script>
  29. var serviceWorkerVersion = null;
  30. var scriptLoaded = false;
  31. function loadMainDartJs() {
  32. if (scriptLoaded) {
  33. return;
  34. }
  35. scriptLoaded = true;
  36. var scriptTag = document.createElement('script');
  37. scriptTag.src = 'main.dart.js';
  38. scriptTag.type = 'application/javascript';
  39. document.body.append(scriptTag);
  40. }
  41. if ('serviceWorker' in navigator) {
  42. // Service workers are supported. Use them.
  43. window.addEventListener('load', function () {
  44. // Wait for registration to finish before dropping the <script> tag.
  45. // Otherwise, the browser will load the script multiple times,
  46. // potentially different versions.
  47. var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
  48. navigator.serviceWorker.register(serviceWorkerUrl)
  49. .then((reg) => {
  50. function waitForActivation(serviceWorker) {
  51. serviceWorker.addEventListener('statechange', () => {
  52. if (serviceWorker.state == 'activated') {
  53. console.log('Installed new service worker.');
  54. loadMainDartJs();
  55. }
  56. });
  57. }
  58. if (!reg.active && (reg.installing || reg.waiting)) {
  59. // No active web worker and we have installed or are installing
  60. // one for the first time. Simply wait for it to activate.
  61. waitForActivation(reg.installing ?? reg.waiting);
  62. } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
  63. // When the app updates the serviceWorkerVersion changes, so we
  64. // need to ask the service worker to update.
  65. console.log('New service worker available.');
  66. reg.update();
  67. waitForActivation(reg.installing);
  68. } else {
  69. // Existing service worker is still good.
  70. console.log('Loading app from service worker.');
  71. loadMainDartJs();
  72. }
  73. });
  74. // If service worker doesn't succeed in a reasonable amount of time,
  75. // fallback to plaint <script> tag.
  76. setTimeout(() => {
  77. if (!scriptLoaded) {
  78. console.warn(
  79. 'Failed to load app from service worker. Falling back to plain <script> tag.',
  80. );
  81. loadMainDartJs();
  82. }
  83. }, 4000);
  84. });
  85. } else {
  86. // Service workers not supported. Just drop the <script> tag.
  87. loadMainDartJs();
  88. }
  89. </script>
  90. </body>
  91. </html>