Swappit exposes two static methods for script management and one static property for instance registry. These are accessed directly on theDocumentation 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.
Swappit class, not on instances.
Swappit.instances
Type:Map<string, Swappit>
A registry of all active Swappit instances, keyed by their handle string. Instances are added to the map when constructed and removed when destroy() is called.
Example
Swappit.updateScriptByContent()
Recreates inline<script> elements in the DOM to force re-execution of their content. When Swappit swaps a region, the browser does not automatically execute <script> tags inside the replaced HTML. Call this method in an update:after event handler to run those scripts.
For each node in the array, the method creates a new <script> element, copies the original textContent into it, and replaces the old node with the new one. The act of inserting a fresh <script> node causes the browser to execute its content.
Syntax
Parameters
Array of inline script DOM nodes (elements without a
src attribute) whose content should be re-executed. Pass the result of Array.from(nodeList) if you have a NodeList.Returns
void
Example
Swappit.updateScriptBySrc()
Reloads external<script src="..."> elements whose src attribute contains matchUrl, appending a ?timestamp=<Date.now()> query parameter to bust the browser cache. The old <script> element is replaced with the new one, causing the browser to re-fetch and re-execute the script.
If the script’s existing
src already contains a query string, the timestamp is appended with ×tamp=... to avoid breaking the existing parameters.Parameters
Substring to match against script
src attributes. Any <script> whose src contains this string will be reloaded. Uses querySelectorAll('script[src*="matchUrl"]') internally.Returns
void
Example
analytics.js?timestamp=1234567890, forcing the browser to fetch and execute a fresh copy.