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
Asked Oct 11 '21 07:10
avatar oasys

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?

Answered Sep 02 '21 at 15:06
avatar  of LisaFC

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 ( 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. (

==> 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.

Answered Sep 06 '21 at 09:05
avatar  of narrenfrei

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?

Answered Sep 06 '21 at 09:17
avatar  of narrenfrei

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 }}
   {{- end }}

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!

Answered Sep 07 '21 at 23:57
avatar  of oasys

After the last comment, I reread your suggestions. I had originally dismissed @LisaFC 's toc_hide suggestion because adding it to a year's also hid the year (in addition to the entries). But, I found something like this (for each year's works as desired:

title: 2019
toc_hide: false
- 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.

Answered Sep 08 '21 at 00:23
avatar  of oasys