In this guide you’ll build a two-page site where clicking a navigation link swaps only the content area — no full page reload, no framework, no build step. By the end you’ll have a workingDocumentation 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.
index.html and about.html where the header and main content update in place when the user navigates between them.
Include Swappit
Add the Swappit script to your page. The CDN is the quickest way to get started:Place this tag before your own
<script> block — Swappit must be loaded before you create an instance.Mark update regions on the main page
Create The string
index.html. Add data-app-update attributes to every region you want Swappit to be able to replace, and add data-swappit-handle="app" to any navigation link you want Swappit to intercept automatically.'app' is the handle. It becomes the prefix in data-app-update. The handle can be any unique string — 'nav', 'main-layout', 'site' — as long as it matches on both pages.Create the target page (about.html)
Create This file does not need a full
about.html alongside index.html. It only needs the same data-app-update regions — Swappit fetches this file in the background and extracts the matching elements from it.<html>, <head>, or <body> structure — Swappit parses the fetched HTML in memory and only reads the update regions from it. A full HTML document works too; Swappit simply ignores everything outside the named regions.Both pages must use the same region names (the values of
data-app-update) for the swap to work. If a region is present in index.html but missing from about.html, Swappit hides it by adding the hidden class to the live element.Try it
Open
index.html in a browser (via a local server, since Swappit uses fetch). Click the About link.Here is what happens under the hood:- Swappit intercepts the click because the link has
data-swappit-handle="app". - It calls
app.update('./about.html')automatically. fetch('./about.html')retrieves the file and parses it in memory.- Swappit finds the
headerandcontentregions in the fetched document. - It replaces the live
data-app-update="header"anddata-app-update="content"elements in the DOM with the new versions — no page reload.
Next steps
Automatic Links
Learn how
data-swappit-handle works in depth — per-link preloading, cache control, and dynamic DOM observation.Declarative Instance
Use the
<swappit-instance> custom element to configure your Swappit instance entirely in HTML, with no JavaScript required.Smart Preloading
Speed up navigation with instant or hover-triggered preloading — fetch the next page before the user even clicks.
History Navigation
Enable browser back and forward button support with
updateUrl and enableHistory options.