Skip to content

Docusaurus Faster #10556

Open
Open

Description

@slorber

Docusaurus v3.6 is out with the Docusaurus Faster options 🥳 🎉

https://docusaurus.io/blog/releases/3.6

Docusaurus Faster

This is a meta-issue for the Docusaurus Faster project.

The goal is to modernize our infrastructure and greatly reduce the time and memory it takes to build a Docusaurus site in production mode, to fix this long-standing issue #4765.

yarn add @docusaurus faster

Before using these flags, you will need to add an extra package encapsulating all the opt-in dependencies:

It includes multiple experimental PRs adding new siteConfig.future.experimental_faster options:

const config = {
  future: {
    experimental_faster: {
      optionName: true
    },
  },
}

We recommend turning them on all at once with a simple boolean shortcut. We also recommend turning future.v4 feature flag on, because some Docusaurus Faster options rely on upcoming changes.

const config = {
  future: {
    v4: true, // opt-in for Docusaurus v4 planned changes
    experimental_faster: true, // turns Docusaurus Faster on globally
  },
}

But you can also turn them on/off one by one to troubleshoot potential problems.

Note that the rspackBundler option requires swcJsLoader, swcJsMinimizer, and lightningCssMinimizer to be enabled first.

It is possible that certain combinations of options do not work, and our CI doesn't cover all possible permutations (only true / false).

It also includes notable memory improvements:

What to expect

With experimental_faster: true, our Docusaurus website builds:

Although rebuilds (with warm ./node_modules/.cache) are not faster (yet), we recommend you enable the experimental_faster: true option to future-proof your site against our new dependencies and report us potential problems you encounter.

Our core plugins/themes are all compatible with this new option, and we expect most community plugins to be compatible out-of-the-box. Some plugins might need minor adjustments to make them compatible with Rspack, and we'll help the community to make our ecosystem compatible with Rspack.

This option is relatively safe to use in production: we have deployed our own website with it already:

  • If your Docusaurus site is standard, it should be fine out of the box
  • If your Docusaurus site is more complex, make sure to test it thoroughly and give us feedback

For Docusaurus plugins authors

Some plugins implementing the configureWebpack() lifecycle hook might need to adjust their code to add support for Rspack.

I will write a guide for them in this sister issue: #10572

Upgrade PRs

Example upgrade PRs to look at, including some benchmarks.

Community websites:

Popular plugins:

Contributing to this issue

We want our community to share feedback on this Docusaurus Faster project.

Please try to adopt it as part of the v3.6+ / canary releases, and tell us how it works for you.

If you encounter problems, please let us know here, and we might create dedicated issues if needed.

This general issue is a great place to follow the Docusaurus Faster project overall, as we try to stabilize it and aim to make it the default for an upcoming major version.

Activity

  1. added
    proposal
    status: needs triage
    and removed
    status: needs triage
    on Oct 4, 2024
  2. sserrata commented on Oct 9, 2024

    @sserrata
    Contributor

    Thanks @slorber, sharing comparison results for our OpenAPI plugin site.

    Cold Build No Optimization

    [PERF] Build > en > Bundling with webpack - 41.58 seconds!
    [PERF] Build > en > SSG > Load App renderer > Load server bundle - 8.49 ms
    [PERF] Build > en > SSG > Load App renderer > Server bundle size = 17.241 MB
    [PERF] Build > en > SSG > Load App renderer > Evaluate server bundle - 225.13 ms
    [PERF] Build > en > SSG > Load App renderer - 234.15 ms
    [PERF] Build > en > SSG > Generate static files - 3.26 seconds!
    [PERF] Build > en > SSG - 3.50 seconds!
    [PERF] Build > en > postBuild() - 10.58 ms
    [PERF] Build > en > Broken links checker - 28.01 ms
    [SUCCESS] Generated static files in "build".
    [PERF] Build > en - 46.38 seconds!
    [PERF] Build - 46.38 seconds!
    [INFO] Use `npm run serve` command to test your build locally.
    ✨  Done in 51.97s.
    

    Cold Build With Experimental Faster Enabled

    [PERF] Build > en > Bundling with webpack - 23.44 seconds!
    [PERF] Build > en > SSG > Load App renderer > Load server bundle - 7.16 ms
    [PERF] Build > en > SSG > Load App renderer > Server bundle size = 17.767 MB
    [PERF] Build > en > SSG > Load App renderer > Evaluate server bundle - 222.76 ms
    [PERF] Build > en > SSG > Load App renderer - 230.31 ms
    [PERF] Build > en > SSG > Generate static files - 1.82 seconds!
    [PERF] Build > en > SSG - 2.06 seconds!
    [PERF] Build > en > postBuild() - 9.49 ms
    [PERF] Build > en > Broken links checker - 27.01 ms
    [SUCCESS] Generated static files in "build".
    [PERF] Build > en - 26.79 seconds!
    [PERF] Build - 26.79 seconds!
    [INFO] Use `npm run serve` command to test your build locally.
    ✨  Done in 32.52s.
    

    Edit from @slorber: results above are still based on Webpack.

    See PaloAltoNetworks/docusaurus-openapi-docs#1003 for the real upgrade.

    Benchmark shows demo site building:

    • 2.7x faster on cold builds
    • 1.2x slower (for now) on warn builds
  3. slorber commented on Oct 10, 2024

    @slorber
    Author
  4. slorber commented on Oct 11, 2024

    @slorber
    CollaboratorAuthor

    The Rspack support has been merged: #10402

    You can try canary 0.0.0-6101 or above to benefit from all the upcoming perf improvements.

    Here's an example PR upgrading the React Native website: react/react-native-website#4268

    How to benchmark

    One way to benchmark this is to use hyperfine with an env variable:

    const config = {
      future: {
        experimental_faster: (process.env.DOCUSAURUS_FASTER ?? 'true') === 'true',
      },
    }

    For cold builds:

    hyperfine --prepare 'yarn clear' --runs 5 'DOCUSAURUS_FASTER=false yarn build' 'DOCUSAURUS_FASTER=true yarn build'

    For warm rebuilds:

    DOCUSAURUS_FASTER=false yarn build
    hyperfine --runs 5 'DOCUSAURUS_FASTER=false yarn build' 'DOCUSAURUS_FASTER=true yarn build'

    Troubleshooting slow builds

    It's possible that enabling this new option does not give you the expected speed increase.

    Perf logger

    You can get a more verbose performance logger with the DOCUSAURUS_PERF_LOGGER=true env variable, giving you the time it takes to execute each step:

    image

    Rsdoctor

    Another option is to use Rsdoctor, which works for both webpack and Rspack.

    It can tell you which loader/plugin/phase is slow while bundling your app.

    For many Docusaurus sites (including ours), the slow loaders are postcss/css-loader, mdx loader, and the image loaders of our ideal image plugin. Despite these slow loaders, Docusaurus Faster builds 3x faster.

    It is possible that a Docusaurus plugin you use slows down your build. Rsdoctor might be able to give you insight on that.

    We'll probably release an official Rsdoctor plugin for Docusaurus, but in the meantime here's a Docusaurus plugin we built to integrate it into our own site: https://github.com/facebook/docusaurus/blob/main/website/src/plugins/rsdoctor/RsdoctorPlugin.ts

  5. o-l-a-v commented on Oct 22, 2024

    @o-l-a-v

    Tested with a relatively large internal documentation site.

    PS > Get-ChildItem -File -Recurse | Group-Object -Property 'Extension' | Sort-Object -Property 'Count' -Descending | Format-Table -Property 'Count', 'Name'
    
    Count Name
    ----- ----
      748 .md
      553 .png
       71 .jpg
       24 .json
       10 .webp
        8 .svg
        5 .order
        4 .py
        3 .drawio
        3 .html
        3 .pdf
        2 .mdx
        2 .xml
        1 .xlsx
        1
        1 .avif
        1 .zip
    
    PS >

    Locally, Windows, Yarn v4.5.1, NodeJS v20.18.0. Used following command in PowerShell for timing the build:

    yarn docusaurus clear; $Stopwatch = [System.Diagnostics.Stopwatch]::StartNew(); yarn build; $Stopwatch.Stop(); $Stopwatch.Elapsed.ToString()
    • 3.5.2: 00:02:32.9615610
    • Canary with experimental_faster: true: 00:01:10.1179920

    We're pretty stoked on that speedup. 😊

  6. sedghi commented on Oct 28, 2024

    @sedghi

    which version of docusaurus comes with this experimental config? since i can't get it to run in 3.5.2

    [ERROR] Error: These field(s) ("future.experimental_faster",) are not recognized in docusaurus.config.js.
    If you still want these fields to be in your configuration, put them in the "customFields" field.
    See https://docusaurus.io/docs/api/docusaurus-config/#customfields
        at validateConfig (/Users/alireza/dev/admin/cornerstone3D.git.worktrees/beta/node_modules/@docusaurus/core/lib/server/configValidation.js:299:15)
        at loadSiteConfig (/Users/alireza/dev/admin/cornerstone3D.git.worktrees/beta/node_modules/@docusaurus/core/lib/server/config.js:39:62)
        at async Promise.all (index 1)
        at async loadContext (/Users/alireza/dev/admin/cornerstone3D.git.worktrees/beta/node_modules/@docusaurus/core/lib/server/site.js:37:97)
        at async loadSite (/Users/alireza/dev/admin/cornerstone3D.git.worktrees/beta/node_modules/@docusaurus/core/lib/server/site.js:136:21)
        at async createReloadableSite (/Users/alireza/dev/admin/cornerstone3D.git.worktrees/beta/node_modules/@docusaurus/core/lib/commands/start/utils.js:50:16)
        at async Command.start (/Users/alireza/dev/admin/cornerstone3D.git.worktrees/beta/node_modules/@docusaurus/core/lib/commands/start/start.js:22:28)
    [INFO] Docusaurus version: 3.5.2
    
  7. sedghi commented on Oct 28, 2024

    @sedghi

    Answering myself, it is 3.5.2-canary-6125, I'll update the speed benchmarks soon

    I'm seeing

    • dev: 15 seconds -> 2 seconds
    • build: +3 mins before giving any error (I'm upgrading to 3.x from 2.x) to 10 seconds with relevant mdx erros

    Nice job

    Update: build is down from +3 minutes to 30 seconds

  8. societymartingale commented on Oct 31, 2024

    @societymartingale

    I ran some informal benchmarks on a Macbook M3 Pro building our Docusaurus site. I cleared the cache after each build. Seeing a 2.5x speedup.

    existing build (s)
    -----------------
    70.2
    72.2
    72.0
    71.5
    72.5
    average: 71.7s
    
    experimental_faster build (s)
    -----------------------------
    31.7
    27.4
    27.0
    27.6
    27.8
    average: 28.3s
    
    speedup = 71.7 / 28.3 = 2.5
    

    Our CI runners are significantly slower than my Macbook, so I'm estimating that it will reduce the build time by 2 minutes in the CI pipeline.

  9. lebalz commented on Nov 1, 2024

    @lebalz
    Contributor

    Wanted to test it on a docusaurus page that uses stage 3 decorators. Is it (or will it be) possible to customize the configuration of swc? (I have no experience so far with swc, but what i understand from the docs, the following should work:

    {
      "jsc": {
        "parser": {
          "syntax": "typescript",
          "decorators": true
        }
      }
    }

    )

  10. slorber commented on Nov 1, 2024

    @slorber
    CollaboratorAuthor
  11. lebalz commented on Nov 4, 2024

    @lebalz
    Contributor

    Thanks for the advice @slorber . I tried it, but somehow swc does not pick up the .swcrc configuration.

    Here is a little repro:

    https://codesandbox.io/p/devbox/sharp-bird-jd7tf5

    With future: { experimental_faster: { swcJsLoader: false } } it compiles and works as intended (click the Click Me Button and check the console log to see it working).

    The used code for the decorators can be compiled by the swc playground when enabling the decorators.

    decorated code example
    type AccessorDescriptor = {
      get: () => number;
      set: (value: number) => void;
    };
    
    type DecoratorContext = {
      name: string;
      kind: string;
    };
    
    function accessorDecorator(
      { get, set }: AccessorDescriptor,
      { name, kind }: DecoratorContext
    ) {
      if (kind === "accessor") {
        return {
          init(initialValue: any) {
            return initialValue ?? 0;
          },
          get() {
            const value = get.call(this);
            // Additional logic can be added here
            return value;
          },
          set(newValue: any) {
            const oldValue = get.call(this);
            console.log("set", name, "=", newValue);
            // Additional logic can be added here
            set.call(this, newValue);
          },
        };
      }
    }
    
    class ExampleClass {
      @accessorDecorator accessor exampleField: number = 1;
    }
    
    export default ExampleClass;

    Maybe the options must be passed to swc explicitely 👉 https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-faster/src/index.ts#L25-L34 ?

    Update 5.11.2024

    The workaround from #10556 (comment) works:

    const config = {
      future: {
        experimental_faster: {
          swcJsLoader: false, /* set it to false here */
          swcJsMinimizer: true,
          swcHtmlMinimizer: true,
          lightningCssMinimizer: true,
          rspackBundler: true,
          mdxCrossCompilerCache: true,
        },
      },
      webpack: {
        jsLoader: (isServer) => {
          const defaultOptions = require("@docusaurus/faster").getSwcLoaderOptions({isServer});
          return {
            loader: 'builtin:swc-loader', // (only works with Rspack)
            options: {
              ...defaultOptions,
              jsc: {
                parser: {
                  ...defaultOptions.jsc.parser,
                  decorators: true
                },
                transform: {
                  ...defaultOptions.jsc.transform,
                  decoratorVersion: '2022-03'
                }
              }
            },
          }
        },
    }

    Thanks @slorber

  12. slorber commented on Nov 4, 2024

    @slorber
    CollaboratorAuthor

    I don't know, will need to investigate @lebalz

    Note that you might still be able to use the old custom js loader option mentioned here: #4765 (comment)

    Didn't try, but pseudo-code:

    const config = {
      webpack: {
        jsLoader: (isServer) => ({
          loader: 'builtin:swc-loader', // (only works with Rspack)
          options: require("@docusaurus/faster").getSwcLoaderOptions({isServer}),
        }),
      },
    }
  13. 38 remaining items

  14. ramnivas commented on Aug 4, 2025

    @ramnivas
  15. slorber commented on Aug 5, 2025

    @slorber
    Author
  16. kdy1 commented on Aug 6, 2025

    @kdy1
  17. added a commit that references this issue on Sep 26, 2025
  18. karl-cardenas-coding commented on Nov 11, 2025

    @karl-cardenas-coding
  19. slorber commented on Nov 14, 2025

    @slorber
    Author
  20. karl-cardenas-coding commented on Nov 14, 2025

    @karl-cardenas-coding
  21. slorber commented on Nov 14, 2025

    @slorber
    CollaboratorAuthor

    Your site uses one of those?

    • the showLastUpdateAuthor and showLastUpdateTime plugin options
    • the sitemap lastmod option

    We have found these options to be a significant bottleneck for many sites due to issuing thousands of git log <filename> calls.


    🆕 In Docusaurus v3.10, we will release:

    • A new VCS API (Version Control System) to give you flexibility to read file update info on your own terms.
    • A new Git-based "git-eager" implementation that reads the whole repository eagerly on docusaurus build instead of issuing thousands of git log <filename> calls.

    More details on the PR: #11512

    The impact on build times can be significant, in particular for:

    • large Git repositories
    • large number of md/mdx files
    • large number of i18n locales
    • all 3 above combined!
  22. karl-cardenas-coding commented on Nov 15, 2025

    @karl-cardenas-coding
  23. tats-u commented on Feb 2, 2026

    @tats-u
    Contributor

    If docusaurus start or docusaurus build is not finished and is stuck at "100% emitting after emit" in Windows with Rspack 1.6.6–1.7.3, try updating Rspack (@rspack/core) to 1.7.4 or later. (I could not find out why this happens) This is suppressed if you disable the persistent cache.

  24. AlbertBrand commented on Feb 20, 2026

    @AlbertBrand

    @alirezamirian @slorber We ran into the same issue and disabled the flag swcJsLoader: false because for some odd reason, Netlify returns an exit code 2 when the flag is enabled. All other CI/CD systems, such as GitHub Actions, work fine. It's only in Netlify that we see this issue.

    I'm seeing a build problem, only when running on GitLab and when swcJsLoader is set to true:

            Error: Can't render static file for pathname "/[REDACTED]"
                at generateStaticFile ([REDACTED]/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]._9ec5c227eab01026f6cdca42e873a4f8/node_modules/@docusaurus/core/lib/ssg/ssgRenderer.js:131:20)
                at async [REDACTED]/node_modules/.pnpm/[email protected]/node_modules/p-map/index.js:57:22 {
              [cause]: ReferenceError: Prism is not defined
                  at 88020 (server.bundle.js:2464:3)
    

    Especially the Prism is not defined feels like an import/transpilation issue inside server.bundle.js. And the stacktrace is not relevant. Strange thing that I can't reproduce it in a local Docker container, it might be a CI env setting that influences the swc build process?

  25. slorber commented on Apr 6, 2026

    @slorber
    CollaboratorAuthor

    FYI, Docusaurus Faster is now stable (#11802).

    It will be enabled by default in Docusaurus v4, and is also used for all newly initialized Docusaurus v3 sites.

    We now have a v4 future flag so that users can prepare their site for Docusaurus v4: future.v4: true or future.v4.fasterByDefault: true.

    In Docusaurus v4, we'll likely introduce a "Docusaurus Slower" mode, requiring a @docusaurus/slower dependency, for those who still want to use webpack/Babel.

    We'll likely drop support for the legacy infrastructure in Docusaurus v5, so please let us know if you are unable to upgrade your site to Docusaurus Faster for any reason!
    (Please open a bug report with a minimal repro, not a full/complex OSS repo)

  26. AlbertBrand commented on Apr 17, 2026

    @AlbertBrand

    I'm seeing a build problem, only when running on GitLab and when swcJsLoader is set to true:

            Error: Can't render static file for pathname "/[REDACTED]"
                at generateStaticFile ([REDACTED]/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]._9ec5c227eab01026f6cdca42e873a4f8/node_modules/@docusaurus/core/lib/ssg/ssgRenderer.js:131:20)
                at async [REDACTED]/node_modules/.pnpm/[email protected]/node_modules/p-map/index.js:57:22 {
              [cause]: ReferenceError: Prism is not defined
                  at 88020 (server.bundle.js:2464:3)
    

    Figured this out. 1) Run docusaurus clear locally to make sure environments are identical and 2) this is triggered by a bug in Redocusaurus.. Fix is incoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions