Skip to content

Commit 563cb62

Browse files
committed
chore(preload): use preload if modulepreload not supported
preload doesn't preparse the JS but it is supported by very old iOS devices
1 parent 2ba58bb commit 563cb62

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/qwik/src/core/qrl/preload.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,22 @@ export const loadBundleGraph = (element: Element) => {
101101
});
102102
};
103103

104+
let canModulePreload: boolean | null = null;
104105
const makePreloadLink = (bundle: BundleImport, priority: boolean) => {
105106
const link = document.createElement('link');
106-
link.rel = 'modulepreload';
107+
if (canModulePreload === null) {
108+
if (link.relList.supports('modulepreload')) {
109+
canModulePreload = true;
110+
} else {
111+
canModulePreload = false;
112+
}
113+
}
114+
link.rel = canModulePreload ? 'modulepreload' : 'preload';
107115
link.href = bundle.$url$!;
108116
link.fetchPriority = priority ? 'high' : 'low';
109-
link.as = 'script';
117+
if (!canModulePreload) {
118+
link.as = 'script';
119+
}
110120
document.head.appendChild(link);
111121
};
112122

0 commit comments

Comments
 (0)