Swappit has a built-in content cache. Preloading fetches a URL and stores the parsed HTML document without updating the DOM. When the user then clicks a link, the swap happens instantly from cache — no waiting for a network round trip.Documentation 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.
Preload Modes
Swappit supports three preload modes that control when a URL is fetched relative to user interaction:false (default)
Content is fetched only when the user clicks the link. No pre-fetching occurs.
hover
Content is fetched on
mouseenter (desktop) or touchstart (mobile). Ideal for secondary pages.instant
Content is fetched as soon as the page initializes, before any user interaction. Best for high-priority destinations.
Global Preload Default
Set a default preload mode for all links managed by an instance at construction time:data-swappit-handle="app" will now preload on hover unless overridden individually.
Per-Link Preload
Override the global default on any individual link using thedata-preload attribute:
data-preload attribute on a link always takes precedence over the instance’s global preload option. Only the exact values "instant" and "hover" are recognized — any other value is treated as no preload.
Programmatic Preload with preloadContents()
Use preloadContents() to populate the cache ahead of time from JavaScript:
preloadContents() fetches all URLs in parallel using Promise.allSettled(), so a single failing URL does not block the others. It also deduplicates the URL list automatically using Set before fetching — passing the same URL twice is safe.
After the batch completes, Swappit logs a summary (when log: true):
Cache Invalidation
By default,update() uses the cache if the URL has already been fetched. Pass false as the second argument to force a fresh download:
data-use-cache attribute: