Skip to content

Commit 80016a7

Browse files
author
Heiner Pöpping
committed
Change async css chunks from blocking to preload
1 parent 4d27c2f commit 80016a7

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/util/collectCssChunks.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ const loadRemoteInfo = async (url: string) => {
3535
throw new Error(`Could not load remote info from ${url}`);
3636
}
3737

38+
/**
39+
* Collects the css chunks from all modules rendered during SSR
40+
* @experimental Handling for async chunks is not final and subject to change.
41+
* Eventually a parameter for the rendered html might be added to analyze the async chunks
42+
* @param modules
43+
*/
3844
export const collectCssChunks = async (modules: ModuleContextValueType) => {
3945
const p = Object.values(modules).map(async (module) => {
4046
const info = await loadRemoteInfo(module.url);
@@ -43,10 +49,14 @@ export const collectCssChunks = async (modules: ModuleContextValueType) => {
4349
info?.exposes.forEach((exposes) => {
4450
if (module.modules.has(exposes.path)) {
4551
const { sync = [], async = [] } = exposes.assets?.css ?? {};
46-
[...sync, ...async].forEach((chunk) => {
52+
sync.forEach((chunk) => {
4753
const url = new URL(chunk, module.url);
4854
chunks.push(`<link rel="stylesheet" href="${url}">`)
4955
});
56+
async.forEach((chunk) => {
57+
const url = new URL(chunk, module.url);
58+
chunks.push(`<link rel="preload" href="${url}" as="style" onload="this.rel='stylesheet'">`)
59+
});
5060
}
5161
})
5262
return chunks;

0 commit comments

Comments
 (0)