Navigation without reload (useSpa)
When a domain has useSpa checked, internal links no longer reload the page: bspkSpa (in assets/js/bspk.js) fetches the target URL, compares it zone by zone and swaps only what changed. Navigation feels smoother for the visitor.
The server knows nothing about it: every URL is still served as a complete page. F5, shared links, crawlers and new tabs all keep working. The one thing to remember when you write front-end code: swapped content never goes through DOMContentLoaded or $(document).ready again. Initialise on the bspk:spa:fin event too.
When it is on
The server writes data-spa="1" on <body> (in bspk/tpl-page1.html and tpl-page2) only if all of these hold:
E_WebDomain.useSpa = True;- the user does not have
BSPK_CAN_EDIT_PAGE: an editor always gets full page loads, because the dev panel keeps state tied to the page (tree, selection, undo/redo); - the page is not shown inside a panel iframe (
?modal=in the URL).
bspkSpa.start() runs at load and does nothing without data-spa="1". To test the behaviour, stay logged out, or use an account that cannot edit the page.
Which clicks are intercepted
The browser handles the click itself (classic load) when:
- a modifier key or a non-left button is used;
targetis not_self;- the link has
downloadordata-no-spa; - the link goes to another origin or a non-http(s) protocol;
- it is an anchor on the current page;
- the URL has a file extension (
pdf,zip,csv,xls(x),doc(x), images,mp4,webm,txt,json); - the path starts with
/bspk-file,/bspk-icons,/bweb/login,/bweb/logoutor/bweb/call-action.
Put data-no-spa on any link that must reload the page: a page that relies on a full init you cannot replay, a link to another domain served by the same host…
What one navigation does
- The
bspk:spa:debut{url}event is dispatched; the classbspk-spa-chargeis added on<html>(thin progress bar andprogresscursor, styles injected inline, not Tailwind). fetch(url)with the headerX-Bspk-Spa: 1; a previous navigation still in flight is aborted.- Falls back to a real navigation (
location.href = …) when the response was redirected to another URL (expired session, language redirect), the status is not OK, the target page has nodata-spa="1", or anything throws. - The
<head>is updated without being replaced:title,metadescription / keywords / robots,og:*,canonical,hreflanglinks,<html lang>. Page stylesheets are added if missing, never removed. - Zones are swapped:
- every
[data-spa-zone](header,sidebar-left,sidebar-right,footerin the page shells) is replaced only if its HTML differs; a zone missing from the target is removed, a new one is inserted next to#mainContentParent; #mainContentParentis always replaced;- the
<body>attributesdata-pageuuid,data-ws,data-ws-indicator,data-presence,data-can-edit,data-scope-page,data-scope-recordanddata-spaare copied from the target (presence follows the new page).
- every
history.pushState({bspkSpa: true}), then scroll to top.- The
bspk:spa:fin{url, zones}event is dispatched.
Back/forward (popstate) replays the navigation only for history entries carrying bspkSpa.
Events, and what each is for
| Event | detail | When |
|---|---|---|
bspk:spa:debut | {url} | before the fetch |
bspk:spa:avant-remplacement | {zone} | before a zone's innerHTML is replaced: tear down what you mounted in it |
bspk:spa:apres-remplacement | {zone} | after the zone's inline <script>s were re-run; the URL is not updated yet |
bspk:spa:fin | {url, zones} | after pushState: the place to (re)initialise |
zones lists what changed: a zone name, contenu for #mainContentParent, +name for an inserted zone, -name for a removed one.
Use fin, not apres-remplacement, for anything that calls 4D: the server takes the page language from the Referer of /bweb/call-action, and the address only changes at pushState.
What is replayed for you
- inline
<script>s of swapped zones are re-created so they execute; - TomSelect instances inside a swapped zone are destroyed before the swap;
- on
bspk:spa:fin: listboxes of swapped zones (displayListbox, scroll handler),markListenSearchZones,checkLinkedFields,repaintOnResize, plusloadTomSelectandloadDropZone(inassets/js/base.js).
Not replayed: loadQrCodeScanner, which recreates every scanner without checking whether it already runs. A page whose QR scanner starts on load must be reached by a full navigation: put data-no-spa on the links to it.
Pitfalls
- Your own init code runs once. A site script (a host
/assets/js/*.js, acodeblock) that initialises onDOMContentLoadedorreadydoes nothing after an internal click. Subscribe to the end of navigation as well:
Make the init idempotent: an unchanged zone (same header) is not swapped, so its elements are already initialised.function initMine(root) { /* … */ } document.addEventListener('DOMContentLoaded', () => initMine(document)); document.addEventListener('bspk:spa:fin', () => initMine(document)); - Inline scripts run again on every swap of their zone. Listeners added to
documentorwindowfrom such a script pile up: guard them with a flag onwindow. - Stylesheets accumulate: the CSS of every visited page stays in
<head>. If two pages' stylesheets conflict, scope their rules to their page. - A 301/302 redirect ends the SPA navigation for that click: the browser really navigates to the final URL. This is expected.
- Editors never see this behaviour: to reproduce a visitor's problem, log out.
See also
- Pages and routing —
useSpaamong the domain settings - WebSocket and presence — presence scopes copied from the new
<body> - The listbox — row loading, replayed after navigation

