Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(v2): lazy sidebar categories / collapsibles, reduce html output / build times #5136

Merged
merged 4 commits into from
Jul 14, 2021

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Jul 9, 2021

Motivation

Allowing collapsibles (ie sidebar categories) to be "lazy" can reduce significantly the HTML markup.

Fix #4753

Many sites have very large sidebars and the sidebar markup is responsible for a huge part of the HTML content + build time.

We should avoid rendering collapsed items on the server, and delay rendering until the first expansion.

Note: this can have an SEO impact, as crawlers won't see the whole sidebar anymore, but I believe it's fine because crawlers can still navigate the site through direct sidebar siblings and the next/previous buttons. I also believe crawlers would understand better that certain pages are related together and form "semantic cocoons" because only sidebar siblings/ancestors are rendered now.

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

preview

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@slorber slorber added the pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient. label Jul 9, 2021
@slorber slorber requested a review from lex111 as a code owner July 9, 2021 16:44
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jul 9, 2021
@netlify
Copy link

netlify bot commented Jul 9, 2021

✔️ [V2]

🔨 Explore the source changes: d94cea5

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/60eeedef61ab790008082531

😎 Browse the preview: https://deploy-preview-5136--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Jul 9, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 96
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-5136--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Jul 9, 2021

Size Change: -123 kB (-13%) 👏

Total Size: 850 kB

Filename Size Change
website/build/assets/js/main.********.js 459 kB +952 B (0%)
website/build/docs-tests/index.html 20.5 kB -111 kB (-84%) 🏆
website/build/docs-tests/standalone/index.html 19 kB -94 B (0%)
website/build/docs/index.html 40.2 kB -6.23 kB (-13%) 👏
website/build/docs/installation/index.html 47.8 kB -5.88 kB (-11%) 👏
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 58.8 kB
website/build/assets/css/styles.********.css 89 kB
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.3 kB
website/build/blog/index.html 26.3 kB
website/build/index.html 27.3 kB

compressed-size-action

@slorber
Copy link
Collaborator Author

slorber commented Jul 9, 2021

This can have huge impact on sites with very large sidebars, and a good impact on smaller sites too!

image

Note some very large sites already use a trick to avoid rendering the sidebar on SSR and can save up to 12min build time!: demisto/content-docs#616 (comment)

function DocSidebarBrowser(props) {
  return (
    <BrowserOnly
      fallback={<div>Sidebar...</div>}>
      {() => {
        // Something that should be excluded during build process prerendering.
        return <DocSidebar {...props} />
      }}
    </BrowserOnly>
  );
}

I think current PR is a good compromise to avoid delaying the visibility of the sidebar and keep acceptable perfs. Obviously it will remain faster to simply not render the sidebar on the server.

@slorber
Copy link
Collaborator Author

slorber commented Jul 9, 2021

@jdevalk may I ask you what you think about the potential SEO impacts of server-rendering only a subset of the full sidebar?

@jdevalk
Copy link

jdevalk commented Jul 9, 2021

The risk is that search engines won't follow the links in the parts of the sidebar that aren't rendered immediately. So pages deeper are more clicks away from the main page. Whether that's a problem depends on how many links point to that documentation, but I've seen some docusaurus sites that have such hideously long menu's that that's not ideal either. So in all, especially as it'll make pages faster, I think this is a smart change to make.

@slorber
Copy link
Collaborator Author

slorber commented Jul 9, 2021 via email

# Conflicts:
#	packages/docusaurus-theme-common/src/utils/useCollapsible.tsx
@slorber
Copy link
Collaborator Author

slorber commented Jul 14, 2021

👍 this seems to work fine!

@slorber slorber merged commit 677e53d into master Jul 14, 2021
@slorber slorber changed the title perf(v2): lazy collapsibles, reduce html output and build times perf(v2): lazy sidebar categories / collapsibles, reduce html output / build times Jul 15, 2021
@slorber slorber deleted the slorber/lazy-sidebar-rendering branch August 17, 2021 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Perf: make rendering of collapsed sidebar categories lazy
3 participants