|
21 | 21 | <meta name="viewport" content="width=device-width, initial-scale=1" />
|
22 | 22 | <link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
23 | 23 | <link rel="stylesheet" href="/src/styles.css" />
|
24 |
| - <link rel="manifest" href="/manifest.json" /> |
25 | 24 | <script>
|
26 |
| - // Outside of the local dev server, use the dynamic manifest that |
27 |
| - // passes the query parameters through to the "start_url" property. |
| 25 | + /** |
| 26 | + * Dynamically create <link rel="manifest" /> to enable using Playground with |
| 27 | + * a Blueprint as an offline progressive web app. |
| 28 | + * |
| 29 | + * We don't have a static <link rel="manifest" /> element in the initial HTML |
| 30 | + * because Safari would just go with it and ignore the dynamic updates made below. |
| 31 | + * It has no problem with dynamically created manifest element, though. |
| 32 | + * |
| 33 | + * If this method ever fails, we'll need to rename index.html to index.php and |
| 34 | + * ensure the <link rel="manifest" /> element is shipped in the initial HTML. |
| 35 | + */ |
| 36 | + |
| 37 | + /** |
| 38 | + * On the local dev server, use the static manifest.json file. |
| 39 | + * Outside of the local dev server, use the dynamic manifest that |
| 40 | + * passes the query parameters through to the "start_url" property. |
| 41 | + */ |
| 42 | + let manifestUrl = '/manifest.json'; |
| 43 | + |
| 44 | + /** |
| 45 | + * In production, load a manifest URL that includes the current URL |
| 46 | + * as the "start_url" parameter. |
| 47 | + */ |
28 | 48 | if (window.location.port !== '5400') {
|
29 |
| - let manifestUrl = null; |
30 | 49 | const runningAsPWA = window.matchMedia(
|
31 | 50 | '(display-mode: standalone)'
|
32 | 51 | ).matches;
|
|
58 | 77 | );
|
59 | 78 | }
|
60 | 79 | }
|
61 |
| - |
62 |
| - document.querySelector('link[rel="manifest"]').href = |
63 |
| - manifestUrl.toString(); |
64 | 80 | }
|
| 81 | + const newLink = document.createElement('link'); |
| 82 | + newLink.rel = 'manifest'; |
| 83 | + newLink.href = manifestUrl.toString(); |
| 84 | + document.head.appendChild(newLink); |
65 | 85 | </script>
|
66 | 86 | <link rel="preconnect" href="https://fonts.googleapis.com" />
|
67 | 87 | <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
0 commit comments