Swappit lets you replace targeted sections of your HTML page by fetching new content from a URL and swapping only the elements that match — no full-page reload, no SPA complexity. Add a singleDocumentation 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.
<script> tag, annotate your elements with data- attributes, and you’re done.
Installation
Add Swappit via npm, CDN, or direct download in under a minute.
Quickstart
Build your first partial page update with a working example.
API Reference
Explore the full constructor, instance methods, static methods, and events.
Guides
Deep-dives into configuration, preloading, history navigation, and more.
Why Swappit?
Modern web experiences often need only a sliver of a page to change — a content area, a sidebar, a product listing. Full page reloads feel slow; a full SPA feels like overkill. Swappit sits in the middle: fetch a URL, find elements that share the same handle-baseddata- attributes, and swap them in place.
Zero Dependencies
Pure vanilla JavaScript. No frameworks, no build step required.
Three Usage Patterns
JavaScript API, declarative links with
data-swappit-handle, or the <swappit-instance> custom element.Smart Preloading
Prefetch on hover or instantly — globally or per link — for instant-feel navigation.
History Support
Full browser back/forward button support via the History API.
Event System
Rich lifecycle events:
update:before, update:after, update:error, historyUpdate, reinit, and destroy.DOM Observer
Automatically detects and configures new links added to the DOM dynamically.
Get Started in 3 Steps
The target URL must return an HTML page that contains elements with the same
data-[handle]-update attribute names. Only matching regions are swapped — everything else is ignored.