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

flux-htmx

v1.4.0

Published

Thin server-driven frontend layer on HTMX 4. Shorthand fx-* attributes, lifecycle, presets, prefetch, and toast — without reimplementing htmx.

Readme

flux-htmx

A thin, server-driven frontend layer built on top of HTMX 4.
Shorthand fx-* attributes, lifecycle hooks, presets, smart caching, prefetching, and built-in toasts — without reimplementing htmx.

npm version License: MIT


Why?

HTMX is great. But writing hx-get, hx-target, hx-trigger, hx-swap for every element adds up. Flux adds a minimal preset layer on top:

<!-- Without Flux -->
<a hx-get="/products" hx-target="#main" hx-trigger="click" hx-swap="innerHTML">Products</a>

<!-- With Flux -->
<a fx-get="/products" fx-target="#main">Products</a>

No build step required. Raw hx-* attributes always work as an escape hatch.


Install

npm install flux-htmx

Peer dependency (required for the core builds):

npm install [email protected]

CDN (No Install)

jsDelivr

<!-- Standalone Flux bundle (includes HTMX 4) -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/flux.full.iife.js"></script>

<!-- CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/flux.css" />
<!-- or minified -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/flux.min.css" />

unpkg

<script src="https://unpkg.com/[email protected]/dist/flux.full.iife.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/flux.min.css" />

Tip: Use flux.full.iife.js for CDN (includes everything). Use flux.iife.js for bundlers where htmx is already imported separately.


Quick Start

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>My App</title>
    <meta name="flux-config" content='{"csrf":{"strategy":"meta"}}' />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/flux.css" />
  </head>
  <body>
    <div id="content">
      <a fx-get="/page-2" fx-target="#content" fx-prefetch>Go to Page 2</a>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/flux.full.iife.js"></script>
  </body>
</html>

Preset Attributes

| Attribute | Expands To | Description | | -------------------- | -------------------------------- | ------------------------------------------------------------------- | | fx-get="/url" | hx-get + hx-trigger="click" | GET request on click | | fx-post="/url" | hx-post + hx-trigger="click" | POST request on click | | fx-delete="/url" | hx-delete | DELETE request; add fx-confirm or fx-confirm-dialog when needed | | fx-load="/url" | hx-get + hx-trigger="load" | Fetch on page load | | fx-poll="/url" | hx-get + polling trigger | Periodic polling | | fx-search="/url" | hx-get + native debounce | Debounced search input (eval-free) | | fx-submit="/url" | hx-post on form | Form submission | | fx-autosave="/url" | hx-post + auto-save on input | Auto-save on change | | fx-infinite="/url" | Infinite scroll | Load more on scroll | | fx-realtime="/url" | EventSource (SSE) | Server-Sent Events stream | | fx-page="/url" | Pagination pattern | Page-based navigation | | fx-prefetch | Hover/touch prefetch | Cache on hover before click | | fx-history | hx-push-url="true" | Push URL to browser history on swap |


Modifier Attributes

| Attribute | Description | | ------------------------- | ---------------------------------- | | fx-target="#id" | Override swap target | | fx-swap="outerHTML" | Override swap strategy | | fx-delay="300ms" | Debounce / polling delay | | fx-indicator="#spinner" | Loading indicator element | | fx-confirm="Sure?" | Confirmation prompt text | | fx-disable | Disable element during request | | fx-cache | Cache GET response | | fx-toast | Show built-in success/error toast | | fx-success="Done!" | Message on success | | fx-error="Failed!" | Message on error | | fx-validate | Pre-submit HTML5 form validation | | fx-event="message" | SSE event name (for fx-realtime) |


Built-in Toast (fx-toast)

Add fx-toast to any element:

<button
  fx-delete="/item/1"
  fx-toast
  fx-success="Deleted successfully!"
  fx-error="Failed to delete."
>
  Delete
</button>

Toasts appear bottom-right with smooth slide-in/out animations.


Prefetch (fx-prefetch)

Silently fetches and caches the response on mouseenter, touchstart, or focusin — so clicking feels instant:

<a fx-get="/product/42" fx-target="#main" fx-prefetch> View Product </a>

DOM Interactivity (Alpine Alternative)

Flux completely eliminates the need for Alpine.js or inline JavaScript for common UI interactivity like toggling sidebars, modals, or classes. It provides declarative fx-* action attributes that run entirely client-side without eval(), making them 100% CSP compliant and blazing fast.

Declarative UI Actions

No <script> tags required. All actions default to triggering on click.

<!-- Fades in #sidebar on click -->
<button fx-show="#sidebar">Open</button>

<!-- Fades out #sidebar on click -->
<button fx-hide="#sidebar">Close</button>

<!-- Toggles visibility on click -->
<button fx-toggle="#sidebar">Toggle Menu</button>

<!-- Toggles a class on click (targets self by default) -->
<div fx-class="bg-blue-500">Toggle My Color</div>

<!-- Toggles a class on a specific target -->
<button fx-class="translate-x-full" fx-target=".circle">Toggle Circle</button>

<!-- Fades out and removes ITSELF after 3 seconds -->
<div fx-remove="3s">Item Saved Successfully!</div>

Dropdowns

For menus and dropdowns, reach for the single fx-dropdown directive. It toggles the target's hidden class and coordinates outside-click and Escape close in one handler — so the click that opens a menu can never immediately close it:

<button fx-dropdown="#menu">Toggle</button>

<ul id="menu" class="hidden">
  <li><a href="/profile">Profile</a></li>
  <li><a href="/settings">Settings</a></li>
</ul>

fx-dropdown keeps the trigger's aria-expanded in sync. Clicking the trigger toggles; clicking outside the trigger or menu, or pressing Escape, closes it.

Modals

Modals often need to close when you click outside of them or press the Escape key. Flux has built-in primitives for this:

<button fx-show="#my-modal">Open Modal</button>

<div id="my-modal" class="hidden">
  <!-- Close when clicking outside this specific content box -->
  <div class="modal-content" fx-hide-outside="#my-modal" fx-hide-escape="#my-modal">
    <h2>Hello Modal</h2>
    <button fx-hide="#my-modal">Close</button>
  </div>
</div>

Advanced DOM Scripts (Surreal-style)

If you need custom logic, Flux provides lightweight DOM wrappers me() (the script's parent element) and any() (global selector) for true Locality of Behavior.

<button>
  Toggle Menu
  <script>
    me().on('click', () => {
      any('#menu').classToggle('hidden');
      me().classToggle('active');
    });
  </script>
</button>

Available methods on selected elements: classAdd(), classRemove(), classToggle(), styles(), on(), off(), attribute(), disable(), enable(), fadeOut(), fadeIn(), remove().


Caching

<!-- Cache this response for the default TTL -->
<section fx-load="/stats" fx-cache>...</section>

<!-- Cache with a custom key -->
<section fx-load="/stats" fx-cache fx-cache-key="stats-v1">...</section>

Experimental Offline Queue

fx-offline is opt-in and experimental. It stores plain request parameters in localStorage; it does not preserve files/FormData, headers, target/swap metadata, expiry, or sensitive-field filtering. Do not use it for sensitive or file-bearing requests.


JavaScript API

// Restart with runtime configuration
Flux.reconfigure({
  csrf: { strategy: 'meta', headerName: 'X-CSRFToken' },
  requests: { timeoutMs: 15_000 },
  feedback: { indicator: '#global-spinner' },
});

// Manual cache operations
Flux.cache.invalidate('/products/*');
Flux.cache.clear();

// Diagnostics
Flux.doctor();
Flux.inspect(document.querySelector('#my-form'));

// Dispose / teardown
Flux.dispose();

Plugin System

import { uploadPlugin, optimisticPlugin } from 'flux-htmx';

Flux.use(uploadPlugin);
Flux.use(optimisticPlugin);
Flux.unuse('upload');

ES Module (Bundler)

import Flux from 'flux-htmx';

Flux.reconfigure({ csrf: { strategy: 'meta' } });

Browser Support

All modern browsers (Chrome, Firefox, Safari, Edge). Requires fetch and WeakMap — both available natively in all target environments.


License

MIT © masudranaxpert