mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
ui: speed up page load
This commit is contained in:
15 files changed
+80
-106
No files matched your search
@@ -26,30 +26,30 @@ console.log(
|
||||
);
|
||||
|
||||
window.UiContext = JSON.parse(window.UiContext);
|
||||
window.UserContext = JSON.parse(window.UserContext);
|
||||
try { __webpack_public_path__ = UiContext.cdn_prefix; } catch (e) { }
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
const encodedConfig = encodeURIComponent(JSON.stringify(UiContext.SWConfig));
|
||||
navigator.serviceWorker.register(`/service-worker.js?config=${encodedConfig}`).then((registration) => {
|
||||
console.log('SW registered: ', registration);
|
||||
}).catch((registrationError) => {
|
||||
console.log('SW registration failed: ', registrationError);
|
||||
});
|
||||
const encodedConfig = encodeURIComponent(JSON.stringify(UiContext.SWConfig));
|
||||
navigator.serviceWorker.register(`/service-worker.js?config=${encodedConfig}`).then((registration) => {
|
||||
console.log('SW registered: ', registration);
|
||||
}).catch((registrationError) => {
|
||||
console.log('SW registration failed: ', registrationError);
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const PageLoader = '<div class="page-loader nojs--hide" style="display:none;"><div class="loader"></div></div>';
|
||||
$('body').prepend(PageLoader);
|
||||
$('.page-loader').fadeIn(500);
|
||||
// eslint-disable-next-line camelcase
|
||||
try { __webpack_public_path__ = UiContext.cdn_prefix; } catch (e) { }
|
||||
const PageLoader = '<div class="page-loader nojs--hide" style="display:none;"><div class="loader"></div></div>';
|
||||
$('body').prepend(PageLoader);
|
||||
$('.page-loader').fadeIn(500);
|
||||
|
||||
const [data, HydroExports] = await Promise.all([
|
||||
fetch(`/constant/${UiContext.constantVersion}.js`).then((r) => r.text()),
|
||||
import('./api'),
|
||||
]);
|
||||
const prefetch = Promise.all([
|
||||
fetch(`/constant/${UiContext.constantVersion}.js`).then((r) => r.text()),
|
||||
import('./api'),
|
||||
]);
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
Object.assign(window.UiContext, JSON.parse(window.UiContextNew))
|
||||
const [data, HydroExports] = await prefetch;
|
||||
Object.assign(window, { HydroExports });
|
||||
eval(data); // eslint-disable-line no-eval
|
||||
|
||||
import('./hydro');
|
||||
await HydroExports.initPageLoader();
|
||||
}, false);
|
||||
Reference in new issue
Block a user