mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
feat: Dynamically load katex to improve first-screen loading speed
This commit is contained in:
parent
9321a6ff60
commit
9b3d71f0d2
2 changed files with 16 additions and 6 deletions
|
|
@ -1,10 +1,22 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import katex from 'katex';
|
import type { renderToString as katexRenderToString } from 'katex';
|
||||||
import 'katex/contrib/mhchem';
|
import { onMount } from 'svelte';
|
||||||
import 'katex/dist/katex.min.css';
|
|
||||||
|
|
||||||
export let content: string;
|
export let content: string;
|
||||||
export let displayMode: boolean = false;
|
export let displayMode: boolean = false;
|
||||||
|
|
||||||
|
let renderToString: typeof katexRenderToString | null = null;
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const [katex] = await Promise.all([
|
||||||
|
import('katex'),
|
||||||
|
import('katex/contrib/mhchem'),
|
||||||
|
import('katex/dist/katex.min.css'),
|
||||||
|
]);
|
||||||
|
renderToString = katex.renderToString;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{@html katex.renderToString(content, { displayMode, throwOnError: false })}
|
{#if renderToString}
|
||||||
|
{@html renderToString(content, { displayMode, throwOnError: false })}
|
||||||
|
{/if}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import katex from 'katex';
|
|
||||||
|
|
||||||
const DELIMITER_LIST = [
|
const DELIMITER_LIST = [
|
||||||
{ left: '$$', right: '$$', display: true },
|
{ left: '$$', right: '$$', display: true },
|
||||||
{ left: '$', right: '$', display: false },
|
{ left: '$', right: '$', display: false },
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue