Start

Installation

Use mx the way you like: a script tag, an ES module or an npm package. It's one file with four bindings, and you don't need a build step.

Quick start#

Pick a method. Each tab is the shortest working install, and the sections below cover the variants.

<script src="https://cdn.jsdelivr.net/npm/@tltdsh/mx"></script>

All methods#

CDNOne script tag, globals ready. Recommended.ESMDynamic import from the CDN, no install.npm / yarn / bunInstall from the registry and import in your bundler.DownloadSelf-host the file next to your HTML.

CDN (recommended)#

Add a single script tag. You don't need a build step or an install.

HTML
<!-- jsDelivr (multi-CDN, recommended) -->
<script src="https://cdn.jsdelivr.net/npm/@tltdsh/mx"></script>

<!-- unpkg -->
<script src="https://unpkg.com/@tltdsh/mx"></script>

This exposes four globals: mx, dom, define, components. You're ready to build.

Pinned version

Without a version, the latest release is served automatically. Lock to a specific version:

HTML
<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@tltdsh/mx@1.6.4/mx.min.js"></script>

<!-- unpkg -->
<script src="https://unpkg.com/@tltdsh/mx@1.6.4/mx.min.js"></script>

ESM (CDN import)#

It takes one line, with no install or bundler:

ESM
let { mx, dom, define, components } = await import('https://cdn.jsdelivr.net/npm/@tltdsh/mx/mx.mjs')

Works in any modern browser, with or without a bundler.

Browser runtimes only

The module touches document and Element.prototype while it evaluates, so importing it under Node, Deno or Bun throws ReferenceError: document is not defined.

npm / yarn / bun#

npm install @tltdsh/mx

Use a bundler. The package exports work with Vite, Webpack, Rollup and esbuild:

ESM
import { mx, dom, define, components } from '@tltdsh/mx';

The ESM build exports the four names but does not put them on window. Only the CDN script tag above does that. A bare side-effect import still runs the library (Element.prototype gains render and $attrs) but binds no names in your module:

ESMCounterexample
import '@tltdsh/mx';

document.body.render('works - render() is installed');
mx.h1('ReferenceError: mx is not defined');
No tree-shaking needed

The entire library is under 1 KB brotli. There's nothing to shake.

Download#

Grab the file and self-host:

Drop it next to your HTML:

index.htmlHTML
<!DOCTYPE html>
<html>
<head>
  <script src="mx.min.js"></script>
</head>
<body>
  <script>
    document.body.render(mx.h1('It works!'));
  </script>
</body>
</html>

Verify installation#

Classic script installation: open your browser console and type:

JS
typeof mx     // "function"
typeof dom    // "function"
typeof define // "function"
components    // {}

For ESM, run the same checks inside the module after the named import. Module bindings are not browser globals.

ESM
import { mx, dom, define, components } from '@tltdsh/mx';
console.assert(typeof mx === 'function' && typeof dom === 'function' && typeof define === 'function' && typeof components === 'object');

If all four exist in the chosen scope, mx.js is loaded and ready.

What you're shipping#

FileRawGzipBrotli
mx.min.js2324 B1078 B931 B

For comparison, measured the same way with brotli, React + ReactDOM is about 60 times the size of mx and Preact with hooks about 5 times. The Vue runtime is about 35 times, or about 55 times with the template compiler you need without a build step.

There's no additional CSS or dependencies, just one file with four API bindings. Classic scripts get them as globals and ESM gets them as named exports.

Dependencies also add weight you never use. Libraries overlap, so an app can easily ship three that can all make HTTP requests, and many ship whole subsystems you never call. Tree-shaking helps with ES module code, but it can't pull apart a big CommonJS bundle you don't control, or a dependency of a dependency.