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

htmx-ext-transport

v0.1.0

Published

htmx extension for routing requests through custom transport functions (WASM, IPC, mocks)

Readme

htmx-ext-transport

npm version htmx v4+ License: MIT

Route htmx requests through custom transport functions instead of window.fetch.

Requires htmx v4+. Not compatible with htmx 1.x or 2.x.

Use Cases

  • WebAssembly — route requests to WASM modules in a SharedWorker
  • Electron / Tauri — IPC to a native backend instead of HTTP
  • Testing / Mocking — deterministic responses without a server
  • Hybrid routing — some routes handled locally, some remotely, declared in HTML

Install

CDN

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/htmx.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/htmx-ext-transport"></script>

Or pinned:

<script src="https://unpkg.com/[email protected]/hx-transport.js"></script>

npm

npm install htmx-ext-transport
import 'htmx.org';
import 'htmx-ext-transport';

The extension is automatically active once loaded — no hx-ext attribute required.

Usage

1. Register a Transport

htmx.registerTransport("wasm", async (url, init) => {
  const html = await sendToWasm(url, init);
  return new Response(html, {
    status: 200,
    headers: { "Content-Type": "text/html" }
  });
});

A transport is a fetch-compatible function: (url: string, init: RequestInit) => Response | Promise<Response>.

2. Select It with hx-transport

<div hx-transport:inherited="wasm">
  <button hx-get="/items" hx-target="#main">Load</button>
  <form hx-post="/items/create">...</form>
</div>

All requests within the div will use the wasm transport instead of window.fetch.

Switching Back to Default

Use hx-transport="fetch" to explicitly select the built-in default:

<div hx-transport:inherited="wasm">
  <button hx-get="/items">Load via WASM</button>
  <button hx-get="/api/upload" hx-transport="fetch">Upload to Server</button>
</div>

API

htmx.registerTransport(name, fn)

Registers a named transport function.

| Parameter | Description | |-----------|-------------| | name | Transport name (case-insensitive). "fetch" is reserved. | | fn | Fetch-compatible function: (url, init) => Response \| Promise<Response> |

Returns true if registered, false if the name is invalid/reserved or fn is not a function.

htmx.unregisterTransport(name)

Removes a previously registered transport.

| Parameter | Description | |-----------|-------------| | name | Transport name (case-insensitive) |

Returns true if removed, false if no matching transport was found.

How It Works

The extension hooks into htmx:config:request and:

  1. Reads the hx-transport attribute (with standard htmx inheritance via :inherited)
  2. Looks up the registered transport by name
  3. Sets ctx.fetch to the transport function

The entire downstream pipeline runs normally — swap, OOB, partials, scripts, history, indicators, and other extensions all work as expected because the transport returns a standard Response.

Precedence

If ctx.fetch is already set (e.g., by another extension or a htmx:config:request listener), the transport extension will not override it.

Programmatic ctx.fetch Override

For simple cases you don't need this extension at all. You can listen to htmx:config:request and set ctx.fetch directly based on URL path or any other criteria:

document.body.addEventListener('htmx:config:request', (evt) => {
  const ctx = evt.detail.ctx;
  if (!ctx.request.action.startsWith('/wasm/')) return;
  ctx.fetch = async (url, init) => new Response(await sendToWasm(url, init), {
    status: 200,
    headers: { 'Content-Type': 'text/html' }
  });
});

This approach is composable with hx-transport: a htmx:config:request listener that sets ctx.fetch takes precedence over the extension (since the extension skips if ctx.fetch is already set). So you can use hx-transport for declarative routing and programmatic ctx.fetch for overrides.

Notes

  • hx-transport follows standard htmx inheritance rules — use :inherited for explicit inheritance
  • Transport lookup is case-insensitive ("WASM" and "wasm" are equivalent)
  • Unknown transport names fall back to the default fetch transport
  • Transport functions receive the same (url, init) arguments as window.fetch
  • Non-200 responses from transports go through the normal response pipeline (swap, error events, etc.)
  • If a transport throws, htmx fires htmx:error and completes the request lifecycle normally

License

MIT