When Swappit replaces a region, anyDocumentation 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> tags within the swapped HTML are not automatically executed. This is intentional — use the static helper methods described below to explicitly re-run scripts at the right time.
Why Scripts Don’t Auto-Execute
Swappit deliberately skips script execution during DOM updates for three reasons:- Prevents double initialization — third-party libraries (sliders, maps, widgets) often break or duplicate elements if their setup function runs more than once.
- Avoids re-running analytics — page-view tracking and other one-shot scripts should only fire when you explicitly choose to send them.
- Gives you full control — you decide which scripts need to run after a swap and exactly when they run.
Re-Running Inline Scripts
UseSwappit.updateScriptByContent() inside the update:after event to re-execute inline <script> tags found in updated regions.
<script> DOM nodes. For each node it:
- Creates a new
<script>element with the sametextContent. - Replaces the original node with the new one.
<script> node into the DOM forces the browser to execute its content, even if an identical script has run before.
Reloading External Scripts by URL Match
UseSwappit.updateScriptBySrc() to reload external scripts whose src attribute matches a given string.
- Queries all
<script src="...">elements whosesrccontains the match string. - Removes each matching script from the DOM.
- Re-inserts a new
<script>with a?timestamp=...(or×tamp=...if the URL already has a query string) cache-busting query parameter appended — forcing the browser to download a fresh copy.
Complete Example
Swappit handles
<noscript> elements specially during DOM updates: it sets textContent = innerHTML on each <noscript> in the cloned region. This preserves the noscript content as plain text so it renders correctly in browsers where JavaScript is enabled, matching standard browser behavior.