Skip to content

Commit 431bf78

Browse files
committed
Optimization: chunk up all coding languages
Even though the service worker will proactively cache them in the browser, the browser will not have to load them, parse them, interpret them unless these languages are actually used. Less JS to load, less waiting.
1 parent cda71b4 commit 431bf78

File tree

4 files changed

+339
-116
lines changed

4 files changed

+339
-116
lines changed

client/codemirror/editor_state.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ import { createSmartQuoteKeyBindings } from "./smart_quotes.ts";
4444
import { documentExtension, pasteLinkExtension } from "./editor_paste.ts";
4545
import type { TextChange } from "./change.ts";
4646
import { postScriptPrefacePlugin } from "./top_bottom_panels.ts";
47-
import { languageFor } from "../languages.ts";
47+
import {
48+
lazyLanguages,
49+
languageFor,
50+
loadLanguageFor,
51+
} from "../languages.ts";
4852
import { plugLinter } from "./lint.ts";
4953
import { buildExtendedMarkdownLanguage } from "../markdown_parser/parser.ts";
5054
import { safeRun } from "@silverbulletmd/silverbullet/lib/async";
@@ -462,6 +466,13 @@ export function buildMarkdownLanguageExtension(client: Client): Extension[] {
462466
support: new LanguageSupport(lang),
463467
});
464468
}
469+
if (info in lazyLanguages) {
470+
return LanguageDescription.of({
471+
name: info,
472+
load: async () =>
473+
new LanguageSupport((await loadLanguageFor(info))!),
474+
});
475+
}
465476
return null;
466477
},
467478
addKeymap: true,

0 commit comments

Comments
 (0)