mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17: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
@@ -1,5 +1,6 @@
|
||||
window.Hydro = {
|
||||
extraPages: [],
|
||||
preload: [],
|
||||
components: {},
|
||||
utils: {},
|
||||
node_modules: {},
|
||||
@@ -19,9 +20,28 @@ console.log(
|
||||
`,
|
||||
);
|
||||
|
||||
window.UiContext = JSON.parse(window.UiContext);
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
window.UiContext = JSON.parse(window.UiContext);
|
||||
|
||||
// eslint-disable-next-line
|
||||
try { __webpack_public_path__ = UiContext.cdn_prefix } catch (e) { }
|
||||
// eslint-disable-next-line
|
||||
try { __webpack_public_path__ = UiContext.cdn_prefix } catch (e) { }
|
||||
|
||||
import('./hydro');
|
||||
// Locale & langs
|
||||
const { version, payload } = JSON.parse(localStorage.getItem('hydro-constant') || '{}');
|
||||
if (version === UiContext.constantVersion) {
|
||||
eval(payload[0]); // eslint-disable-line no-eval
|
||||
payload.shift();
|
||||
window.Hydro.preload = payload;
|
||||
import('./hydro');
|
||||
} else {
|
||||
fetch(`/constant?version=${UiContext.constantVersion}`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
eval(data.payload[0]); // eslint-disable-line no-eval
|
||||
localStorage.setItem('hydro-constant', JSON.stringify(data));
|
||||
data.payload.shift();
|
||||
window.Hydro.preload = data.payload;
|
||||
import('./hydro');
|
||||
});
|
||||
}
|
||||
}, false);
|
||||
Reference in new issue
Block a user