html★ exposes a simple JavaScript API for programmatic control.

Global Object

When loaded via script tag, html★ exposes the htmlstar global:

Core Functions

htmlstar.init(root)

Initialize html★ on a DOM subtree. Called automatically on page load and after swaps.

htmlstar.resolveAll(element)

Get all resolved attributes for an element.

Request Functions

htmlstar.getURL(element)

Get the URL from an element.

Persistence Functions

htmlstar.clearPersisted(element)

Clear the persisted value for an element.

htmlstar.clearPersistedByPrefix(prefix, scope)

Clear all persisted values matching a prefix.

htmlstar.closeAllSSE()

Close all SSE connections.

htmlstar.stopPolling(element)

Stop polling for an element.

Cache Functions

htmlstar.clearCache()

Clear the entire response cache (memory and sessionStorage).

htmlstar.getCacheStats()

Get cache statistics.

htmlstar:request-end

Fired when a request completes successfully, after the content has been swapped in and history updated.

Detail properties: id, url, method, target, swap, select, element, status, ok, fromCache

The fromCache property is true when the response was served from cache rather than a live fetch. The status and ok properties reflect the HTTP response (these are undefined for cached responses).

htmlstar:request-error

Fired when a request fails (network error, non-OK HTTP status, etc.).

Detail properties: id, url, method, target, swap, select, element, error

htmlstar:request-abort

Fired when a request is aborted, for example by queue control replacing an in-flight request with a newer one.

Detail properties: id, url, method, target, swap, select, element

htmlstar:navigated

Fired on window after history is updated following a successful request. Useful for updating active navigation state or other UI that depends on the current URL.

Detail properties: url, target, swap

Catching Events on Parent Elements

Because the request events bubble, you can listen on a parent element to handle events from all html★-enhanced elements within it:

Utility Functions

htmlstar.debounce(fn, ms)

Create a debounced function.

htmlstar.throttle(fn, ms)

Create a throttled function. Executes immediately on first call, then at most once per interval.

Configuration

htmlstar.getConfig()

Get the current configuration.

Constants

htmlstar.DEFAULTS

The built-in default values (read-only).