Skip to content

Commit 5910c0b

Browse files
authored
⚡ 优化资源加载, 并行加载异步资源 (#574)
1 parent 4d060e4 commit 5910c0b

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

src/app/service/service_worker/resource.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ export class ResourceService {
5050
}
5151

5252
public async getScriptResources(script: Script, load: boolean): Promise<{ [key: string]: Resource }> {
53+
const [require, require_css, resource] = await Promise.all([
54+
this.getResourceByType(script, "require", load),
55+
this.getResourceByType(script, "require-css", load),
56+
this.getResourceByType(script, "resource", load),
57+
]);
58+
5359
return {
54-
...((await this.getResourceByType(script, "require", load)) || {}),
55-
...((await this.getResourceByType(script, "require-css", load)) || {}),
56-
...((await this.getResourceByType(script, "resource", load)) || {}),
60+
...require,
61+
...require_css,
62+
...resource,
5763
};
5864
}
5965

@@ -97,10 +103,17 @@ export class ResourceService {
97103

98104
// 更新资源
99105
async checkScriptResource(script: Script) {
106+
const [require, require_css, resource] = await Promise.all([
107+
this.checkResourceByType(script, "require"),
108+
this.checkResourceByType(script, "require-css"),
109+
this.checkResourceByType(script, "resource"),
110+
]);
111+
112+
// wait https://github.com/tc39/proposal-await-dictionary
100113
return {
101-
...((await this.checkResourceByType(script, "require")) || {}),
102-
...((await this.checkResourceByType(script, "require-css")) || {}),
103-
...((await this.checkResourceByType(script, "resource")) || {}),
114+
...require,
115+
...require_css,
116+
...resource,
104117
};
105118
}
106119

0 commit comments

Comments
 (0)