Swappit’s declarative API is built on HTMLDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/soyleninjs/swappit/llms.txt
Use this file to discover all available pages before exploring further.
data-* attributes. There are three groups: update region attributes (on the elements being swapped), link attributes (on <a> tags), and <swappit-instance> attributes.
Update Region Attributes
These attributes go on elements you want Swappit to swap whenupdate() is called. Both the source page and the destination page must use matching attribute names and values for the swap to occur.
If a region name exists in the current DOM but is absent from the fetched page, Swappit adds the class
hidden to that element rather than removing it entirely. If a region exists only in the fetched page but not in the current DOM, it is ignored.Identifies an update region. Replace
[handle] with your instance’s handle string. The attribute value is the region name used to match elements between the current page and the fetched page.Example: for an instance with handle "app", use data-app-update="content". Swappit will replace the element carrying data-app-update="content" in the live DOM with the element of the same name found in the fetched HTML.Controls the sequence in which update regions are swapped. Elements that have this attribute are updated first, sorted by their value in ascending order. Elements without this attribute are updated last, in document order.Example: for handle
"app", use data-app-update-order="1".Example
Link Attributes
These attributes go on<a> tags to make them automatically trigger Swappit updates on click. Swappit’s DOM observer detects these links when the page loads and whenever new ones are added dynamically.
Connects the link to a Swappit instance by handle. When the link is clicked, Swappit calls
instance.update(href) using the link’s href as the URL. The value must exactly match the handle of an existing Swappit instance.Preload mode for this specific link. Overrides the instance-level
preload option for this link only. Accepted values:"instant"— the URL is fetched and cached as soon as the DOM observer registers the link."hover"— the URL is fetched and cached when the user hovers over the link (desktopmouseenter) or touches it (mobiletouchstart).
preload option. If that is also false, content is only fetched on click.Whether to use the cache when this link is clicked.
"true"(default) — if the URL is already cached,update()skips the network fetch."false"— always fetches fresh content from the network when the link is clicked, regardless of the cache.
Example
swappit-instance Attributes
These attributes configure the<swappit-instance> custom element, which provides a fully declarative way to create or reconfigure a Swappit instance directly in HTML.
When <swappit-instance> connects to the DOM, it checks Swappit.instances for an existing instance with the given data-handle. If one is found, it calls reinit() with the new options. If not, it calls new Swappit(handle, options).
The instance handle. Must be unique among all active Swappit instances, unless you intentionally want to reconfigure an existing one (in which case
reinit() is called automatically).Enables colorized console logging when the attribute is present on the element. No value is needed — the presence of the attribute is sufficient.
Enables browser address bar updates on each
update() call when present. No value needed.Enables back/forward browser navigation when present. Requires
data-update-url to also be present on the same element.Default preload mode for all
<a data-swappit-handle> links managed by this instance. Accepted values: "hover" or "instant". Any other value (including omitting the attribute) results in false — no default preloading.