4 · Swap

Sparke atomically replaces the page from memory – then updates meta, focus and history.

This is the instant bit. Sparke takes the page it already holds in memory and atomically swaps it into the live document – no diffing, no virtual DOM.

What gets replaced

  • If both the current and incoming pages have exactly one <main>, only <main> is replaced.
  • Otherwise the <body> contents are replaced.

On each swap Sparke also updates the <title> and <meta name="description">, applies the incoming page's per-page <head> CSS, and sets aria-current="page" on the matching nav link.

History, scroll & accessibility

  • Navigation uses pushState; the address bar shows the final URL after any redirect.
  • Forward navigation scrolls to the top (or the #hash target); Back/Forward restores from cache, including form values.
  • After a swap, focus moves to <main> and the new title is announced via a visually-hidden aria-live region.

Sparke never executes scripts from fetched pages. To re-run page code after a swap, see Re-running scripts.