mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: 优化资源加载
This commit is contained in:
1 parent
fffacdc63c
commit
c8a0d48a41
7 files changed
+111
-143
No files matched your search
@@ -24,25 +24,7 @@ function buildSequence(pages, type) {
|
||||
}
|
||||
|
||||
async function load() {
|
||||
if (UiContext.extraPages) {
|
||||
const tasks = [];
|
||||
const ts = new Date().getTime();
|
||||
for (const page of UiContext.extraPages) {
|
||||
const head = document.getElementsByTagName('head')[0];
|
||||
const script = document.createElement('script');
|
||||
if (page.includes('.module.')) script.type = 'module';
|
||||
script.src = page;
|
||||
head.appendChild(script);
|
||||
tasks.push(new Promise((resolve) => {
|
||||
script.onload = resolve;
|
||||
}));
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
const time = new Date().getTime() - ts;
|
||||
if ((process.env.NODE_ENV !== 'production' && time > 16) || time > 256) {
|
||||
console.warn(`Extra pages loading took ${time}ms`);
|
||||
}
|
||||
}
|
||||
for (const page of window.Hydro.preload) await eval(page); // eslint-disable-line no-eval
|
||||
|
||||
const pageLoader = new PageLoader();
|
||||
|
||||
|
||||
Reference in new issue
Block a user