Skip to content
DocsLit

Engineering 3 min read

Why we built DocsLit on Lit and web components

Why we chose web components for documentation instead of React and MDX: less JavaScript for readers, no hydration, a simpler build, and no imports for authors.

A docs page is mostly text, and yet many docs sites ship a full JavaScript framework to show it. We built DocsLit on web components for documentation because we wanted readers to download as little as possible and authors to write as little ceremony as possible. This post explains the reasoning, with numbers from our own measurements.

What a docs page actually needs

Look at a typical page in any docs site. Headings, paragraphs, lists, code blocks, a table or two. Then a handful of interactive pieces: tabs, an accordion, a copy button on code, a search box. That's it.

The static part is the vast majority of the page, and the browser can render it with no help. The interactive part needs some JavaScript, but only on those specific elements. A framework built to manage application state across a whole page is a lot of machinery for that job.

The cost of a framework runtime

React-based docs tools pay for three things that a text-heavy page barely uses.

  • The runtime. React plus ReactDOM is roughly 28 KB gzipped before your docs add a single word, and tools typically add a router and their own bootstrapping code on top.
  • Hydration. The page is rendered to HTML on the server, then the browser downloads JavaScript to rebuild the same tree in memory and attach listeners. For static headings and paragraphs, that work changes nothing the reader can see.
  • The build toolchain. MDX needs a compiler, a bundler integration and a JSX runtime. That's more configuration to maintain and more time on every build.

Here are the client-side JavaScript numbers from our Why DocsLit page. These are DocsLit's own measurements and comparisons, gzipped, and they will shift as the tools release new versions.

ToolClient JS (gzipped)Hydration
DocsLit16 KBNone
Nextra 4106 KBFull page
Fumadocs161 KBPartial (RSC)
Docusaurus 3250 to 400 KBFull page

The 16 KB is Lit plus all 54 built-in components, served from your own site as a single ES module. Lit itself is about 5 KB of that.

How web components upgrade in place

A web component is a custom HTML tag that the browser knows how to enhance. Our build writes plain HTML, including tags like <wc-tabs>. The browser paints that HTML immediately. When the component script loads, customElements.define tells the browser what the tag means, and each element upgrades where it already sits.

There's no virtual DOM to build and no tree to diff against what's on screen. Only the interactive elements run code. Everything else stays the static HTML it always was, which is why we can say there's no hydration step to debug.

Lit keeps this small. It gives you reactive properties, scoped styles and a tiny template function, and little else. DocsLit vendors it into docslit-vendor/ and loads it through an import map, so there's no extra CDN request.

A simpler build and simpler authoring

The build is the same Markdown pipeline most MDX tools use, built from unified, remark and rehype, except it outputs HTML rather than JSX. The output is then minified with esbuild. No bundler runs, so there are no route bundles to split and no bundler config to tune. Our docs list a short set of production dependencies, where React-based tools commonly pull in hundreds or thousands of packages.

Authoring gets simpler too. In an MDX-based tool, a callout looks like this:

import { Callout } from '@/components/Callout'

<Callout type="warning">
  You need to restart the server after changing config.
</Callout>

In DocsLit, it's this:

<wc-callout type="warning" title="Restart required">
You need to restart the server after changing config.
</wc-callout>

No import, because the component is registered in the browser rather than in a module graph. Because it's a standard custom element, the same tag also works in plain HTML anywhere, including outside our toolchain.

Your own components work the same way. Drop a .js file that extends LitElement into components/, name the tag with a wc- prefix, and use it in any page. docslit dev hot-reloads it, and docslit validate recognizes it. The custom components guide has the full walkthrough.

When React tools make sense

This isn't the right trade for every project. Be honest about your needs:

  • Deeply interactive pages. If your docs embed full React applications, such as playgrounds or editors, a React-based tool gives you direct access to that ecosystem.
  • An existing React design system. Reusing those components as they are beats porting them to web components.
  • Per-request server logic. Tools like Mintlify and Nextra can run server-side code on each page load. DocsLit produces static files.

If your docs are mostly text with a few interactive parts, we think the lighter approach wins. Our post on how AI agents read your docs covers another benefit of plain, predictable output.

To try it, run npx docslit init and look at what the build produces. If you're coming from another tool, the Mintlify migration guide shows the one-command path.