npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@knno/jsx-optimizer

v2.2.1

Published

Compile-time optimizer for @knno/jsx — template cloning and precise DOM bindings

Readme

@knno/jsx-optimizer

npm version License: MIT

Compile-time optimizer for @knno/jsx — replaces runtime JSX dispatch with template cloning and precise DOM bindings.

Adds ~0 runtime overhead: no virtual DOM, no runtime createElement loops, no prop-type dispatching. The compiler analyzes your JSX at build time and generates optimized JavaScript that directly manipulates the DOM.

Installation

npm install -D @knno/jsx-optimizer
# or
pnpm add -D @knno/jsx-optimizer

Requires @knno/jsx as a runtime dependency.

Usage

Vite

// vite.config.ts
import { optimizer } from '@knno/jsx-optimizer/vite';

export default {
  plugins: [optimizer()],
};

Rollup / Rolldown

// rollup.config.js
import { optimizer } from '@knno/jsx-optimizer/rollup';

export default {
  plugins: [optimizer()],
};

esbuild / tsup

// esbuild config
import { optimizer } from '@knno/jsx-optimizer/esbuild';

await esbuild.build({
  plugins: [optimizer()],
});
// tsup.config.ts
import { optimizer } from '@knno/jsx-optimizer/esbuild';

export default {
  esbuildPlugins: [optimizer()],
};

Programmatic

import { transform } from '@knno/jsx-optimizer';

const result = transform(sourceCode, 'app.tsx');
// → { code: optimizedJavaScript, map?: sourceMap }

How It Works

The optimizer replaces JSX with a two-phase execution model:

Phase 1 — Build Time (the optimizer)

// Your source code
<tr class={() => selected({ key: row.id }) === row.id ? "danger" : ""}>
  <td class="col-md-1">{row.id}</td>
  <td class="col-md-4"><a onClick={handler}>{value("label", () => row.label)}</a></td>
</tr>

↓ Compiler analyzes and generates:

// Template — created once, cloned for each row
const _tpl0 = (() => {
  const t = document.createElement("template");
  t.innerHTML = `<tr><td class="col-md-1"></td><td class="col-md-4"><a></a></td></tr>`;
  return () => t.content.firstElementChild.cloneNode(true);
})();

// Binding code
(() => {
  const root = _tpl0();           // 1 cloneNode instead of 8 createElement calls
  const td1 = root.firstElementChild;
  const a1 = td1.nextElementSibling.firstElementChild;

  track(root, ctx => {            // Dynamic className — skips setAttr
    ctx.skipUpdateDOM = true;
    root.className = expr();      // Direct property assignment
  });
  appendAll(td1, row.id);         // Dynamic text
  a1.addEventListener("click", handler); // Event
  appendAll(a1, value("label", ...)); // Reactive child
  return root;
})();

Phase 2 — Runtime (what the browser executes)

| | Without optimizer | With optimizer | |---|---|---| | createElement per row | 8× | 0 (1× cloneNode) | | jsxGen prop dispatch | 6× | 0 (direct assignment) | | appendAll type checks | 6× | 2× (only dynamic children) | | DOM update path | generic updateDOM | precise (node.data / el.className) |

Safety

The optimizer follows a "degrade gracefully, never crash" principle:

  • Optimizable elements (all-static props + optimizable children) → template + bindings
  • Unoptimizable elements (components, spread attrs, dynamic children containing JSX) → falls back to runtime jx() — functionally identical to no optimizer.
  • Nested JSX in expressions → inner elements are individually optimized and referenced in the outer expression.

No matter the JSX complexity, the output is always semantically equivalent to the runtime-only version.

When Not to Use

The optimizer adds a build step and slightly increases bundle size (~4%). Skip it if:

  • You're prototyping or debugging (runtime mode gives clearer stack traces)
  • Your app has very few JSX elements (the overhead isn't worth it)
  • You're using a build tool without plugin support (use the transform() API directly)

Requirements

  • Node.js: >= 20.9.0
  • Build tool: Vite, Rollup, Rolldown, esbuild, tsup, or any tool with a transform hook

License

MIT © Thor Qin