-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.js
More file actions
44 lines (37 loc) · 1.1 KB
/
bootstrap.js
File metadata and controls
44 lines (37 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { getPrimaryCdnImportUrls } from './modules/cdn.js'
/*
* Preload only the modules needed for the initial render path.
* - Included: core runtime + React runtime modules used immediately.
* - Excluded: optional style compilers (sass/less/lightningCssWasm), which stay lazy.
* Keep this list aligned with cdnImports keys in modules/cdn.js.
*/
const preloadImportKeys = [
'cssBrowser',
'jsxDom',
'jsxTransform',
'jsxReact',
'react',
'reactDomClient',
'idb',
]
const isImportMapPrimary =
typeof globalThis !== 'undefined' && globalThis.__KNIGHTED_PRIMARY_CDN__ === 'importMap'
const ensureModulePreloadLinks = hrefs => {
for (const href of hrefs) {
const existing = document.head.querySelector(
`link[rel="modulepreload"][href="${href}"]`,
)
if (existing) {
continue
}
const link = document.createElement('link')
link.rel = 'modulepreload'
link.href = href
link.crossOrigin = 'anonymous'
document.head.append(link)
}
}
if (!isImportMapPrimary) {
ensureModulePreloadLinks(getPrimaryCdnImportUrls(preloadImportKeys))
}
await import('./app.js')