CalDOM JS Logo

An agnostic, reactive & minimalist (3kb) JavaScript UI library with direct access to native DOM.

Just ~

0.04x

Slower than Vanilla JS

at unit level

Loads ~

925%

faster than React

at initialization

Achieve near

Native

performant DOM updates

View benchmark results against Vanilla JS, Vue JS, React JS, jQuery & more.

Instead of pulling you into a library-specific magical world, CalDOM let you fully access the DOM directly while keeping the reactivity.

A 2-in-1 virtual-DOM & no-virtual-DOM approach if you will.

So you could take full advantage of native APIs & mix it with other libraries to gain superior performance & flexibility in the development process.

Zero tooling, zero dependencies, zero new syntax, just pure JS.

Why CalDOM?

This was a lightweight jQuery alternative I made myself years ago & kept on improving it slowly. Also, I wanted to stay close to the native DOM API & vanilla JavaScript. Looking back, it paid really well. Then React & Vue JS happened.

In my opinion, the reactive UI approach bought a huge productivity improvement from the perspective of the developer. Also, it enabled a lot of beginner developers to navigate the programming landscape more easily.

However, this shift also moved people away from the core stuff that’s happening under the hood. As a result, sometimes we have to struggle a lot to find solutions within the library’s limits, which are sometimes hilariously dead simple & performant to implement with native APIs.

CalDOM tries to solve this by being 100% interoperable with the native DOM. I hope this will be helpful for developers with similar requirements.

Hello World

Use it as a chainable DOM traverser and a manipulator, a lightweight jQuery alternative.

We use _ (underscore) to access CalDOM.

Hello World - Reactive

Build reactive components. Use it as a lightweight React JS/Vue JS alternative.

Not using classes, similar to React Hooks, but simpler.

Hello World - Reactive (ES6)

Also works as an extended ES6 class.

Reactive Native DOM Elements

Native DOM Node is a first-class citizen. Also, a CalDOM instance is just a wrapper around them.

This agnostic interoperability allows for an infinite amount of powerful integrations.

Make existing HTML reactive

Not a fan of rendering & virtual-DOM thingies? Use CalDOM to update() pre-defined HTML content reactively.

CalDOM's API is inspired by jQuery.

Name:
Age:

Summon the power of both worlds!

Efficiently update() the DOM directly and/or proceed to virtual-DOM render if it's more suitable.

Use this.$ to hold direct DOM Node references. CalDOM keeps them in sync even when render() drastically alter the DOM structure.

There’s a lot going on here. In fact, this is the essence of CalDOM's approach.

When there is an update() function defined, CalDOM calls it instead of calling the render(). This gives us a chance to avoid expensive virtual-DOM diffing and update the DOM directly. The first render() get executed regardless and note we ask CalDOM to remember the direct H1 element using this.$.title = _(…).elem there.

The state changes are batched because it’s obviously very expensive to update the DOM on each state variable change. CalDOM waits for main thread to be idle via requestAnimationFrame and then execute render()/update() efficiently.

Hence, the update() function retrieve two additional arguments as changed_keys & changes_count. This is what state variables changed & how many changes batched since the last render. These can be used to decide whether it’s suitable to update the DOM directly. If not, we can simply proceed with the render() by returning true. Since CalDOM’s basic building box is the native DOM Element, it can switch between render() & update() seamlessly.

In above example, the name change after the 1-second timeout is handled by the update() function. Thus, it execute this.$.title .textContent = “…” directly without any expensive virtual-DOM involvement.

Use HTML to create

Similar to JSX, but with vanilla HTML & JavaScript. No compilers required.

Supercharge Native Web Components

CalDOM integrates seamlessly with Web Components.

Use CalDOM to create stateful & reactive Web Components. It also accepts web components as inputs.

You can use these custom elements in HTML code natively as usual.

Create future-ready declarative modern web apps. Currently, native browser support for Web Components is at 95% & expected to play a primary role in future web development.🔮

You can even make jQuery reactive

Basic building box of CalDOM is just native Node/Element. Thus, making it compatible with almost any DOM library on the web.

Todo App - Non Reactive

CalDOM does not dictate your coding style or approach. It's super flexible & scalable from a single element to large nested implementations.

Todo App - Reactive

CalDOM renders a virtual-DOM and efficiently updates only changed elements in the actual DOM.

Multiple renders are batched to only run once.

Todo App - Multiple Nested Reactive Components

CalDOM plays nicely with nested reusable reactive components and takes care of all DOM updates efficiently.

No matter how deeply nested, components only get re-rendered if their state is changed.

CalDOM also runs on Node JS

Use CalDOM for server side rendering.

You can use a library like JS-DOM to implement a browser context on the server.

Fetching and rendering content generated in the server.

Please note that we did not use classes to keep the examples simple without HTML & CSS. But in practice, always prefer using external CSS over directly setting CSS on elements due to obvious reasons. CalDOM has addClass(), removeClass() methods to facilitate this.

Multiple element instances, built-in XPath support & there is much more

View more examples in the Documentation

Get Started

CDN

Use it as a module

Browser Compatibility

CalDOM is extensively tested on Chromium. Firefox & other browsers to be tested specifically. CalDOM is using native, time-tested official DOM API under the hood. Thus, it should work just fine with any modern browser. Minimum browser support based on MDN compatibility specs is listed below.

Except,

Limitations

CalDOM does not address bugs and loosely implemented web standards of legacy browsers like IE.