Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): handle everything in bootstrap

Elian Doran7a088c5b7d57
diff --git a/apps/client/src/index.html b/apps/client/src/index.html
index 0a3e9dc0ee..79eee73a3b 100644
--- a/apps/client/src/index.html
+++ b/apps/client/src/index.html
@@ -13,11 +13,6 @@
<body id="trilium-app">
<noscript><%= t("javascript-required") %></noscript>
- <script>
- // hide body to reduce flickering on the startup. This is done through JS and not CSS to not hide <noscript>
- document.getElementsByTagName("body")[0].style.display = "none";
- </script>
-
<div class="dropdown-menu dropdown-menu-sm" id="context-menu-container" style="display: none"></div>
<!-- Required for match the PWA's top bar color with the theme -->
diff --git a/apps/client/src/index.ts b/apps/client/src/index.ts
index df5c6a8537..588ebe361d 100644
--- a/apps/client/src/index.ts
+++ b/apps/client/src/index.ts
@@ -1,9 +1,6 @@
-import $ from "jquery";
-
async function bootstrap() {
- (window as any).$ = $;
- (window as any).jQuery = $;
-
+ showSplash();
+ await initJQuery();
await setupGlob();
await loadBootstrapCss();
loadStylesheets();
@@ -13,6 +10,12 @@ async function bootstrap() {
hideSplash();
}
+async function initJQuery() {
+ const $ = (await import("jquery")).default;
+ (window as any).$ = $;
+ (window as any).jQuery = $;
+}
+
async function setupGlob() {
const response = await fetch(`/bootstrap${window.location.search}`);
const json = await response.json();
@@ -93,8 +96,13 @@ async function loadScripts() {
}
}
+function showSplash() {
+ // hide body to reduce flickering on the startup. This is done through JS and not CSS to not hide <noscript>
+ document.body.style.display = "none";
+}
+
function hideSplash() {
- $("body").show();
+ document.body.style.display = "block";
}
bootstrap();