how to optimize for large sites - JavaScript docsy
I'm exploring migrating an existing site to use docsy. The blog portion of the site has about 7800 short entries, grouped by year. Hugo run is slow, but more importantly the generated content is huge. Generated index pages for each of the (16) years are around 500KB each, with a total content over 3GB. What options can I change to reduce the page sizes and generation time?
From looking at the generated HTML, most of the size is in the sidebar. Ideally, I'd just have a sidebar that just links to each directory/year. I've tried many combinations of the documented options, but haven't found anything that meets these needs.
Start building sites …
hugo v0.87.0+extended darwin/amd64 BuildDate=unknown
| EN
-------------------+-------
Pages | 7874
Paginator pages | 771
Non-page files | 7
Static files | 50
Processed images | 0
Aliases | 17
Sitemaps | 1
Cleaned | 0
Total in 37022 ms
5 Answer:
Eep, that is a lot of sidebar entries (and yes, building a big sidebar is slow because it recurses through everything). You could just have a manual navbar for the blog - swap in your own version of the navbar file for the blog section with your per-year links. Or you could set toc_hide: true
in the section index pages of everything but the top-level "year" section.
@narrenfrei, you are our navbar whiz, any other ideas?
There are some different aspects to think about:
- The time for generating the HTML files could be a bit reduced, by activating the caching option
.ui.sidebar_cache_limit
(https://www.docsy.dev/docs/adding-content/navigation/#section-menu-options). But with so many pages, it should be activated by default already. - Speed for the visitor shouldn't be a problem, is it?
- I'm afraid, that the size of the complete website will be hard to reduce. With the actual parameters there is no option, if I can my remember correctly.
So what possibilities are there theoretically to reduce the size of the complete website?
- Reduce the size of the sidebar menu by adding a parameter to only generate the menu entries for the current active menu path and the direct child pages of the current page.
- Disadvantages: No foldable menu structure possible and more time for generating the whole site, because caching not possible.
- Generate really only 1 file containing the sidebar menu and import it in every page. (https://stackoverflow.com/questions/16132341/how-to-create-a-template-in-html)
==> These options are only ideas from my side and are not built in in Docsy at the moment! ==> My own opinion: I would try to learn to live with this big site size. The concept of Hugo (and other static site builders) is to have a simple HTML file for each page.
One more thought: What kind of navigation do you really need in a blogging section? I think, a complete sidebar navigation is really a overkill, isn't it? So as @LisaFC said, maybe you the best would be to disable the complete sidebar navigation?
Yes, disabling the full sidebar (by wrapping the recursive call to section-tree-nav-section
in sidebar-tree.html
) seems to make a big difference. Site size went from over 3GB to less than 650MB, and index pages are now all under 100KB. Build time is better but still slow, from 37 down to 25 seconds.
diff --git i/layouts/partials/sidebar-tree.html w/layouts/partials/sidebar-tree.html
index 258267b..29611df 100644
--- i/layouts/partials/sidebar-tree.html
+++ w/layouts/partials/sidebar-tree.html
@@ -62,10 +62,12 @@
<ul class="ul-{{ $ulNr }}{{ if (gt $ulNr 1)}} foldable{{end}}">
{{ range $pages -}}
{{ if (not (and (eq $s $p.Site.Home) (eq .Params.toc_root true))) -}}
+ {{ if (not (and (not $s.Parent.IsHome) (eq .Section "blog" ))) -}}
{{ template "section-tree-nav-section" (dict "page" $p "section" . "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" $ulShow) }}
{{- end }}
{{- end }}
+ {{- end }}
</ul>
{{- end }}
</li>
I had hoped there was a Params setting for this, but I don't see anything that would do that. I don't know hugo enough to know if there's a way to have different partials for each section, so I've copied the whole sidebar-tree.html
into my local layouts/partials
directory and added the check for the Section to the if statement.
Thanks for the help!
After the last comment, I reread your suggestions. I had originally dismissed @LisaFC 's toc_hide
suggestion because adding it to a year's _index.md
also hid the year (in addition to the entries). But, I found something like this (for each year's _index.md
) works as desired:
---
title: 2019
toc_hide: false
cascade:
- toc_hide: true
---
This solution has the same size and similar performance numbers as the earlier custom partial solution, but is much cleaner. Thanks again.
Read next
- [Bug Report] <el-time-select> 设置了 :editable="false" 后,组件会自动变为 disabled 状态 - Vue element-plus
- PrestaShop Connections source / http referrer database index - PHP
- Halide How to best do fuzzy comparison for floats C++
- netdata Missing network graph for some cgroup containers - C
- Error! No file exists at output path '<path><file>.strings'. - BartyCrouch
- Mailspring Pro Annual Upgrade Issue - Mailspring
- Use nps to play the p2p live video streaming for remote driverless vehicle surveillance. - nps
- Problem with JavaScript Obfuscator package - bytenode