When you addDocumentation 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-swappit-handle="my-handle" to an <a> tag, Swappit intercepts clicks on that link, prevents the default browser navigation, and calls update() with the link’s href automatically. You never need to write an onclick handler — just mark your links with the attribute, create a Swappit instance with the matching handle, and Swappit does the rest.
Basic usage
Adddata-swappit-handle to your anchor tags and create the matching instance in a script block. The links are wired up automatically on initialization:
./page1.html, extracts regions tagged data-app-update, and swaps them into the current page — no reload required.
Per-link preload configuration
Each link can declare its own preload strategy using thedata-preload attribute. Three modes are available:
No data-preload
Content is fetched only when the user clicks the link. Best for pages that are rarely visited.
data-preload="hover"
Content is fetched when the user hovers (desktop) or touches (mobile) the link — before the click completes. Gives a head start without fetching everything upfront.
data-preload="instant"
Content is fetched as soon as the page loads. Best for the pages most likely to be visited next.
Per-link cache control
By default, Swappit uses its content cache when a link is clicked. To force a fresh network request for a specific link — bypassing any previously cached version — setdata-use-cache="false":
data-use-cache (or setting it to "true") uses the cached version if one exists.
Global preload default
Instead of addingdata-preload to every link individually, you can set a default preload mode for all links managed by an instance:
data-swappit-handle="app" that do not have their own data-preload attribute will inherit hover preload behavior.
Individual data-preload attributes on a link always override the global default:
Automatic detection of dynamic links
Swappit starts aMutationObserver when an instance is created. This observer watches document.body for new child elements — so any <a data-swappit-handle="app"> added to the DOM after initialization is automatically wired up with the same click and preload behavior as links that existed at startup:
innerHTML, appendChild, a client-side rendering library, or any other DOM manipulation method.
Advantages
Zero JS in markup
No
onclick handlers or inline scripts required. All wiring happens through a single data-swappit-handle attribute.Flexible preload per link
Mix and match
"instant", "hover", and no preload across different links on the same page.Automatic dynamic detection
The MutationObserver picks up links injected by JavaScript after page load — no reinitialization needed.
Per-link cache control
Mark individual links with
data-use-cache="false" to always fetch fresh content for time-sensitive pages.