This note records a round of optimizations made to the knowledge section of my blog.
The main issues fell into two categories:
Both directly affect real-world usability.
The bundle problem on the knowledge page was not caused by Markdown alone. The issue was loading the entire Markdown ecosystem up front.
The heaviest parts at the beginning were:
markdown-rendererIf all of those are loaded during initial render, then even a plain document with no diagrams and no code blocks still pays the cost.
The fix was layered lazy loading.
Only load Markdown rendering logic when a document is actually opened.
If there are no code blocks in the article, code highlighting should not be part of the initial cost.
mermaid fence is presentMermaid still auto-renders, but the component and chart engine are only loaded when a real ```mermaid block is present.
After this round of changes, the build output of markdown-renderer dropped from roughly 1.1 MB to around 325 KB. mermaid.core still cost about 585 KB, but that cost became conditional and no longer applied to every document.
The knowledge page is not just about bundle size. Reading details matter too.
If the mobile sidebar has too much inertia, it feels floaty, and that effect is even more obvious inside a drawer panel.
So I added an extra layer of handling to make scrolling feel tighter and more controlled.
This does not show up in the bundle report, but it has a direct impact on daily usage.
The knowledge page now records:
After a refresh, if the document still exists, the page restores the same article and the same scroll position.
That way, the user does not have to find the document again or manually scroll back to where they stopped.
There is an important detail in persisted reading state: you cannot blindly trust old records.
If the document that was opened last time has already been removed, the page should not keep trying to restore it.
The handling here is:
That keeps the knowledge page from landing on broken content or behaving strangely because of stale records.
Optimization for a page like this cannot be measured by bundle size alone.
A complete optimization pass should cover:
Only when those layers are handled together does the knowledge page move from merely usable to genuinely smooth.