mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
72.45k stars 6.6k forks source link

Bundle common dependencies into the main file #4617

Open sidharthv96 opened 1 year ago

sidharthv96 commented 1 year ago

Currently, mermaid is "too small". The initial bundle lacks everything required to render a diagram. We use lazy loading to load the diagrams as required.

But, this means that there is added network latency, as we'll only download the diagrams after parsing the text. There is a noticeable delay in live editor due to this.

I think we should include either a) the commonly used diagrams with default renderer or b) flowchart only or c) the common shared libs by most used diagrams in the main bundle.

Yes, this will increase the bundle size, but the overall UX would be better too. The new diagrams, layout engines and heavyweight features, all can still be lazy loaded.

aloisklink commented 1 year ago

But, this means that there is added network latency, as we'll only download the diagrams after parsing the text.

I wonder if Prefetch might help with this, e.g. something like:

<link rel="modulepreload" href="path/to/lazy-imported-flowchart.js"/>
<link rel="modulepreload" href="path/to/lazy-imported-git.js"/>
<link rel="modulepreload" href="path/to/lazy-imported-xxxxx1.js"/>
<link rel="modulepreload" href="path/to/lazy-imported-xxxxx2.js"/>
<link rel="modulepreload" href="path/to/lazy-imported-xxxxx3.js"/>
<link rel="modulepreload" href="path/to/lazy-imported-xxxxx4.js"/>

It would be something that people would have to manually add to their HTML file, though.