-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Is your feature request related to a problem? Please describe.
After addressing the problem of memory overflow (issue #3362, pr #3366), I ended up producing a bundle that, although worked fine, turned out to be very large in size. Especially when compared to the original content size.
I investigated the produced html source tree and found each of them contains a copy of their corresponding navbar and sidebar, parsed into html template.
Describe the solution you'd like
Instead of hard-coding the sidebar (and maybe the navbar) as html templates into each entry file, provide a configuration switch to fall back to client side rendering with their data chunked separately as JSON files.
Describe alternatives you've considered
Not applicable
Additional context
To provide an idea of the scale of size, here is a summary of related objects in my project:
File | Size | Description |
---|---|---|
nav.json | 10KB | Serialized nav object |
sidebar.json | 414KB | Serialized sidebar object |
cache/ | 25MB | Cached raw html files before conversion to vitepress |
dist/ | 1.7GB | Bundle produced by vitepress |
And here is a link of the deployed site: x.z-yx.cc
Validations
- Follow our Code of ConductRead the docs.Read the Contributing Guidelines.Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Zhengqbbb, septatrix and vasfvitorZhengqbbb and vasfvitor
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
zhangyx1998 commentedon Dec 21, 2023
I am happy to work on a PR regarding this if someone could provide me an idea of where to look at.
brc-dd commentedon Dec 21, 2023
Try setting
metaChunk: true
in your vitepress config. It won't skip SSR but will be better than having the data on each page.zhangyx1998 commentedon Dec 21, 2023
It did reduce the overall size from
1.7GB
to1.2GB
.I compared the results with and without the flag. Sidebar and nav items did NOT go away as you told me.
I noticed the following changes to a specific html file as an example:
Would you think it helpful to have an option that leaves the sidebar and nav items for client side rendering?
brc-dd commentedon Dec 21, 2023
Can you try patching
node_modules/vitepress/dist/client/theme-default/Layout.vue
directly to wrap theVPNav
andVPSidebar
components with<ClientOnly>
? If the results are promising, we can try making their client side rendering configurable.There is another potential optimization that can be done for space - an option to ditch the SPA routing - if the whole side is re-rendered every time one opens a page or clicks a link to open a page, we don't need JS files other
*.lean.js
(except few chunks like theme/framework/app). This could theoretically reduce the size by nearly half. But might not seem good experience for end users 🤔zhangyx1998 commentedon Dec 21, 2023
It worked great! Here is a comparison for all 3 conditions:
metaChunk
config optionmetaChunk
, andClientOnly
for VPNav, VPLocalNav and VPSidebarI also noticed significant speedup for bundling. Memory pressure was reduced as well.
In addition, here is what I expect the config to look like:
Or we can provide a wrapper like
markRaw
in Vue:A demo internal implementation for
clientOnly
markers:sengoku-f commentedon Mar 20, 2025
I used the ClientOnly scheme, reducing the size of dist from 270MB to 76MB.
maoist2009 commentedon Mar 31, 2025
So any configable? or we should wait for the next release?
zhangyx1998 commentedon Mar 31, 2025
I just created a PR for this.