index.html 3.8 KB

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