intercooler.js → htmx Migration Guide

The purpose of this guide is to:

πŸ”—Before you begin

It is worth noting the difference in approach between what Intercooler set out to do and what htmx is doing.

Intercooler tried to provide custom html attributes for most of it’s functionality. This is evident in it’s longer list of attributes, many of which could be described as convenience or client-side-focused in nature.

htmx follows the approach of trying to keep the core small, with a smaller set of available attributes that are mostly focused on content loading and swapping.

This capability is augmented in primarily 2 ways:

  1. Extensions. The htmx extension framework allows for custom extensions/plugins to achieve specific functionality. An example of this is the dependencies mechanism baked into Intercooler, which is not present in htmx core. but available via an extension. There are also other extensions which enables new behavior that Intercooler was not capable of out the box, e.g. the preload extension

  2. Using the htmx events system with vanilla javascript, alpine.js or hyperscript. Hyperscript is a small, open scripting language designed to be embedded in HTML, inspired by HyperTalk and is a companion project of htmx.

htmx also contains functionality which is not present in Intercooler. That is outside of the scope of this guide.

Finally, it’s worth noting that this is still a work in progress and is liable to change over time.

πŸ”—Migration Information

The rest of this guide is laid out as a set of tables, each of which attempts to map the following common functional areas of Intercooler onto the htmx equivalents:

πŸ”—Attributes

Note: For certain Intercooler attributes (mostly client-side specific attributes, e.g. the ic-action and associated attributes) there are no direct htmx equivalents. Instead, there is a small, expressive language available called hyperscript, (see http://hyperscript.org), which is designed to be embedded in HTML and acts as a seamless companion to htmx. It allows you to achieve the same behavior as some of especially the client-side focused Intercooler attributes, but in a more flexible and open manner.

See the htmx documentation on hyperscript for practical examples, as well as more on the philosophy behind hyperscipt.

Intercoolerhtmx
ic-actionNone. Use Hyperscript, e.g. <button _="on click add .clicked">Add The "clicked" Class To Me</button>. See the htmx documentation on hyperscript and hyperscript documentationfor more examples
ic-action-targetNone. Use the Hyperscript target expression, e.g. <div _="on click set .button.style.color to 'red'">Set All Buttons To Red</div>
ic-add-classNone. Use Hyperscript, e.g. <button _="on click add .clicked">Add The "clicked" Class To Me</button>. See the htmx documentation on hyperscript and hyperscript documentation for more examples
ic-append-fromNone. Equivalent functionality can be achieved by using for example hx-get and hx-swap with value beforeend
ic-attr-srcNone. No direct equivalent functionality exists (TBC)
ic-confirmhx-confirm
ic-delete-fromhx-delete
ic-depshx-trigger="path-deps" along with path-deps="/foo/bar". (Requires the path-deps extension)
ic-disable-when-doc-hiddenNone. No direct equivalent functionality exists (TBC)
ic-disable-when-doc-inactiveNone. No direct equivalent functionality exists (TBC)
ic-enhancehx-boost
ic-fix-idsNone. No direct equivalent functionality exists (TBC)
ic-get-fromhx-get
ic-global-includeNone. hx-include can be used to achieve similar functionality
ic-global-indicatorNone. hx-indicator can be used to achieve similar functionality
ic-history-elthx-history-elt
ic-includehx-include
ic-indicatorhx-indicator
ic-limit-childrenNone. No direct equivalent functionality exists (TBC)
ic-local-varsNo direct equivalent. hx-vars could be used to facilitate.
ic-on-beforeSendNone. Use Hyperscript in conjunction with events (e.g. htmx:beforeRequest). See the htmx documentation on hyperscript and hyperscript documentation for more examples
ic-on-beforeTriggerNone. Use Hyperscript in conjunction with events (e.g. htmx:beforeRequest). See the htmx documentation on hyperscript and hyperscript documentation for more examples
ic-on-completeNone. Use Hyperscript in conjunction with events (e.g. htmx:afterRequest). See the htmx documentation on hyperscript and hyperscript documentation for more examples
ic-on-errorNone. Use Hyperscript in conjunction with events (e.g. htmx:afterRequest). See the htmx documentation on hyperscript and hyperscript documentation for more examples
ic-on-successNone. Use Hyperscript in conjunction with events (e.g. htmx:afterRequest). See the htmx documentation on hyperscript and hyperscript documentation for more examples
ic-patch-tohx-patch
ic-pause-pollingNone. Techniques like load polling could be used
ic-pollNone. The equivalent can be achieved by triggering a load on schedule, e.g. <div hx-get="/news" hx-trigger="every 2s"></div>. See the documentation on polling
ic-poll-repeatsNone. The equivalent can be achieved by triggering a load on schedule, e.g. <div hx-get="/news" hx-trigger="every 2s"></div>. See the documentation on polling
ic-post-errors-toNone. Errors can be trapped via events and logged via the htmx.logger mechanism
ic-post-tohx-post
ic-prepend-fromThe hx-swap attribute with value set to beforeend could be used to achieve the same outcome
ic-prompthx-prompt
ic-push-urlhx-push-url
ic-push-paramsParameters are automatically pushed in the case of a GET in htmx
ic-put-tohx-put
ic-remove-afterNone. See the htmx documentation on hyperscript for an example on how to implement it using hyperscript
ic-remove-classNone. Use Hyperscript, e.g. <button class="red" _="on click remove .red">Remove The "red" class from me</button>. See the htmx documentation on hyperscript and hyperscript documentationfor more examples
ic-replace-targetThe hx-swap attribute with value set to outerHTML could be used to achieve the same outcome
ic-scroll-offsetNone. No direct equivalent functionality exists
ic-scroll-to-targetSee the scroll and show modifiers on the hx-swap attribute
ic-select-from-responsehx-select
ic-srcNone. Use hx-get in conjunction with triggers or the path-deps extension
ic-sse-srchx-sse
ic-style-srcNone. No direct equivalent functionality exists (TBC)
ic-swap-stylehx-swap
ic-switch-classNone. See the htmx documentation on _hyperscript for an example on how to implement it using _hyperscript and the htmx:beforeOnLoad event
ic-targethx-target
ic-transform-responseNone. The client-side-templates extension enables JSON response transformation via templating engines like mustache, handlebars or nunjucks
ic-transition-durationNone. Equivalent functionality can be achieved by relying on the nature of htmx’s swapping mechanism and CSS transitions
ic-trigger-delayUse hx-trigger with modifiers
ic-trigger-fromUse hx-trigger with from: clause
ic-trigger-onhx-trigger
ic-verbNone. By default htmx sends the actual http method. You can however non-GET verbs to POST via the method-override extension

πŸ”—Request parameters

Intercoolerhtmx
ic-requestNone. Use HX-Request header
_methodNone. Use method-override extension and its provided X-HTTP-Method-Override header
ic-element-idNone
ic-element-nameNone
ic-target-idNone. Use HX-Target header
ic-trigger-idNone. Use HX-Trigger header
ic-trigger-nameNone. Use HX-Trigger-Name header
ic-current-urlNone. Use the HX-Current-URL header
ic-prompt-valueNone. Use the HX-Prompt header

πŸ”—Request headers

Intercoolerhtmx
X-IC-RequestHX-Request
X-HTTP-Method-OverrideX-HTTP-Method-Override

πŸ”—Response headers

Intercoolerhtmx
X-IC-TriggerHX-Trigger, HX-Trigger-After-Settle, HX-Trigger-After-Swap. See documentation for more details
X-IC-RefreshHX-Refresh
X-IC-RedirectHX-Redirect
X-IC-ScriptNone. No direct equivalent functionality exists (TBC)
X-IC-CancelPollingNone. Respond with HTTP response code 286 to cancel polling.
X-IC-ResumePollingNone. No direct equivalent functionality exists
X-IC-SetPollIntervalNone. If using load polling, respond with content that contains a different load interval.
X-IC-OpenNone. No direct equivalent functionality exists (TBC)
X-IC-PushURLHX-Push
X-IC-RemoveNone. No direct equivalent functionality exists (TBC)
X-IC-TitleNone. No direct equivalent functionality exists (TBC)
X-IC-Title-EncodedNone. No direct equivalent functionality exists (TBC)
X-IC-Set-Local-VarsNone. No direct equivalent functionality exists (TBC)

πŸ”—Events

Note: All htmx events are fired in both Camel and Kebab casing.

Intercoolerhtmx
log.icNone. Equivalent achieved via htmx.logger. See Events & Logging documentation
beforeAjaxSend.ichtmx:configRequest
beforeHeaders.icNone. No direct equivalent functionality exists (TBC)
afterHeaders.icNone. No direct equivalent functionality exists (TBC)
beforeSend.ichtmx:beforeRequest
success.ichtmx:afterOnLoad
after.success.icApproximate equivalent: htmx:beforeSwap
error.ichtmx:sendError or htmx:sseError or htmx:responseError or htmx:swapError or htmx:onLoadError (TBC)
complete.ichtmx:afterRequest
onPoll.icNo direct equivalent. When using load polling, the [htmx:load event] could potentially be used
handle.onpopstate.ichtmx:historyRestore (TBC)
elementAdded.ichtmx:load
pushUrl.ictbd
beforeHistorySnapshot.ichtmx:beforeHistorySave

πŸ”—JavaScript API methods

Intercoolerhtmx
Intercooler.refresh(eltOrPath)PathDeps.refresh() (requires the path-deps extension)
Intercooler.triggerRequest(elt, handler)htmx.trigger()
Intercooler.processNodes(elt)htmx.process()
Intercooler.closestAttrValue(elt, attr)htmx.closest() can be used with any selector
Intercooler.verbFor(elt)None. No direct equivalent functionality exists (TBC)
Intercooler.isDependent(elt1, elt2)None. No direct equivalent functionality exists (TBC)
Intercooler.getTarget(elt1)None. No direct equivalent functionality exists (TBC)
Intercooler.processHeaders(elt, xhr)None. No direct equivalent functionality exists (TBC)
Intercooler.ready(func(elt))htmx.onLoad()
LeadDyno.startPolling(elt)None. No direct equivalent functionality exists (TBC)
LeadDyno.stopPolling(elt)None. No direct equivalent functionality exists (TBC)

πŸ”—Meta tags

Intercoolerhtmx
<meta name="intercoolerjs:use-data-prefix" content="true"/>None. You can simply use the data- prefix without specifying a meta tag. htmx will automatically recognize htmx attributes like this: <a data-hx-post="/click">Click Me!</a>
<meta name="intercoolerjs:use-actual-http-method" content="true"/>None. By default htmx sends the actual http method. You can however change the verb for all non-GET requests to POST via the method-override extension