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>let { mx, dom, define, components } = await import('https://cdn.jsdelivr.net/npm/@tltdsh/mx/mx.mjs')npm install @tltdsh/mx<script src="mx.min.js"></script>All methods#
CDN (recommended)#
Add a single script tag. You don't need a build step or an install.
<!-- 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:
<!-- 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:
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.
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/mxyarn add @tltdsh/mxbun add @tltdsh/mxUse a bundler. The package exports work with Vite, Webpack, Rollup and esbuild:
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:
import '@tltdsh/mx';
document.body.render('works - render() is installed');
mx.h1('ReferenceError: mx is not defined');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:
<!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:
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.
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#
| File | Raw | Gzip | Brotli |
|---|---|---|---|
mx.min.js | 2324 B | 1078 B | 931 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.