All options are passed in an object as the second argument toDocumentation 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.
new Swappit(handle, options). Every option defaults to a falsy value — Swappit is zero-config by default and works without any options at all.
Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
log | boolean | false | Enables colorized console logging at 4 severity levels |
updateUrl | boolean | false | Updates the browser address bar URL on each update() call |
enableHistory | boolean | false | Enables back/forward browser navigation. Requires updateUrl: true |
preload | string|false | false | Default preload mode for links: false, "hover", or "instant" |
Full Configuration Example
Option Interactions
enableHistory: true has no effect without updateUrl: true — the popstate listener is only registered when both options are active.updateUrl: true+enableHistory: false— The URL in the address bar is updated on each navigation usinghistory.replaceState(). The history stack is not extended; the back button returns to the page that existed before Swappit started.updateUrl: true+enableHistory: true— Each navigation adds a new entry to the browser history stack viahistory.pushState(), enabling back and forward buttons.- Only one instance can have both
updateUrlandenableHistoryactive at the same time. Creating a second instance with both options enabled will throw an error.
Updating Options at Runtime
Usereinit() to change options after the instance is created. Options are merged — only the keys you provide are overwritten; all other options keep their current values.
<swappit-instance> custom element is used — it calls reinit() automatically if an instance with the same handle already exists.
Logging Levels
Whenlog: true is set, Swappit writes colorized messages to the browser console. Messages are prefixed with Swappit [handle]: and colored by severity:
| Level | Color | When it appears |
|---|---|---|
info | Blue (#3498db) | General lifecycle events (instance created, etc.) |
success | Green (#2ecc71) | Successful fetches, DOM updates, and preloads |
warning | Yellow (#f39c12) | Non-fatal issues such as duplicate update regions |
error | Red (#e74c3c) | Failed fetches and invalid URL errors |