Most of our products are server-rendered: Node and Express with templates, or Next.js. They are fast to build and easy to reason about, but on a phone they share one weakness. Between the moment a finger taps a link and the moment the next page paints, nothing on the screen changes. Users read that silence as "it froze", tap again, and sometimes submit a form twice. The owner of our products put it plainly after using one of them: there is a hang, and it should act first and load after. This is the small piece of front-end code we now ship in every product, and the traps we hit on the way.
TL;DR
- On every same-site link tap or form submit, show a thin progress bar at the top immediately.
- If the next page takes more than about 350 ms, cover the page with a light shimmer veil that also blocks a second tap.
- The tapped button gets a busy shimmer and stops taking clicks. Buttons that save through
fetchstay busy until the request ends, success or failure. - Where we know the shape of the next page, show a skeleton of that page instead of a blank veil.
- Always undo it: on
pageshow, when the tab comes back, on Escape, and after 12 seconds. A loader that never ends is worse than none.
The problem
A single-page app can change the screen the instant you tap, then fetch data. A server-rendered page cannot: the browser keeps showing the old page until the first bytes of the new one arrive. On a fast connection that gap is short. On a mobile network, inside a WebView app, or when the server is doing real work, it is long enough for a person to doubt that the tap registered.
That doubt has costs. People tap twice and send two bookings or two posts. They press back thinking nothing happened. And the product feels slower than it is, because perceived speed is mostly about how soon something reacts, not how soon it finishes.
Why the usual fix costs too much
The usual fix is to rewrite the front end as a client-side app with its own router and loading states. For products with hundreds of server-rendered screens, help centres and admin panels, that is months of work and a second codebase to keep in step with the first. Per-screen spinners are the other usual fix: they work for the screens someone remembered, and leave every other button silent.
We wanted something that works on every existing page without touching the pages: one script and one stylesheet in the layout.
The fix
The core is a delegated click listener on the document and a few CSS classes on the root element. A simplified version of what runs in Kauthar AI:
document.addEventListener('click', function (e) {
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) return;
var a = e.target.closest('a[href]'); if (!a) return;
if (a.target && a.target !== '_self') return; // new tab
if (a.hasAttribute('download') || a.closest('[data-no-load]')) return;
var u = new URL(a.href, location.href);
if (u.origin !== location.origin || SKIP.test(u.pathname + u.search)) return; // files, exports, print
if (u.pathname === location.pathname && u.search === location.search && u.hash) return;
setTimeout(function () { if (!e.defaultPrevented) go(a); }, 0);
});
function go(el) {
root.classList.add('kl-going'); // bar starts growing now
if (el) el.classList.add('kl-busy'); // the tapped control shimmers
slowT = setTimeout(function () { root.classList.add('kl-slow'); }, 350); // veil
safeT = setTimeout(done, 12000); // never lock the page for good
}
window.addEventListener('pageshow', done); // back/forward cache
The bar is a 3-pixel fixed element whose width animates over 8 seconds to 94% and never reaches the end on its own; the new page replaces it. The veil is a full-screen element that is invisible and click-through until the slow class is added; then it dims the page, sweeps a shimmer across it, and takes pointer events so a second tap cannot get through. Both respect prefers-reduced-motion and reverse the sweep direction in right-to-left layouts.
Forms get the same treatment on submit, with the submit button as the busy element. The setTimeout(…, 0) matters: it lets every page-specific handler run first, so a click that a script cancelled (a confirm dialog, a like button that uses AJAX) never shows a loader.
Skeletons shaped like the destination
In DentX, the dental network, we went one step further. A small function maps the destination path to a page shape (feed, card list, product grid, detail, profile, form, dashboard, map), and the content area is covered by a shimmer skeleton of that shape while the header and bottom tabs stay visible. The tapped menu item turns active at once, as if the new page were already there. The old content is hidden with visibility, never removed, so scroll position and the back/forward cache stay intact. A link can override the guess with data-skel="grid", or opt out with data-no-skel.
DentX also prefetches safe pages on hover or press using Speculation Rules, with a long exclusion list: sign-in, payment, settings, admin, exports, anything with side effects on GET, and anything the server marks no-store.
What went wrong on the way
Downloads that look like pages. A link to an export or a print view does not leave the page. Without the skip list, the loader would start and never end. We skip known file extensions and export, print and download paths, and every new link that downloads a file without an obvious extension must carry the opt-out attribute. The 12-second safety timer exists for the ones we miss.
Links the app opens outside. Inside our mobile WebView apps, some links open in the system browser. The page never unloads, so pageshow never fires. We also clear the loader when the page becomes visible again without having been left.
Navigation by script. The first DentX version only reacted to plain link clicks on pages that had a main content area. Pages that navigate with location.assign after a fetch, and links whose click a page handler prevented before navigating itself, stayed silent. The second version listens to the Navigation API's navigate event for cross-document navigations, falls back to beforeunload where that API is missing, and covers pages without a content area, such as the landing page and help centre.
Next.js prevents every link click. When we ported the engine to our Next.js products, the rule "ignore clicks that were already prevented" silently disabled it: Next's Link prevents the default click to navigate on the client, and those are exactly the taps that need the bar most. In the React version that rule is dropped, and the loader ends when the route changes instead of on pageshow.
Buttons that save with fetch. A save or send button that calls fetch never navigates, so no navigation event covers it. A thin wrapper around fetch marks the button tapped in the last 1.5 seconds as busy while a write request (POST, PUT, PATCH, DELETE) is in flight, and clears it when the request settles, success or failure. Beacons sent with keepalive are ignored.
Result
Every tap now changes the screen at once: the bar is switched on inside the tap handler itself, so it does not wait for the network or the server. A second submit is blocked while the first is on its way. The same engine runs in 11 of our codebases, including Kauthar AI, DentX, Spotra, Curava, ELKASHIER Cloud and G.Academy, with the look adjusted to each product's colours. We do not have a before-and-after measurement of perceived speed to quote; the property we verify on each release is that every button, walked on a 390-pixel phone screen, reacts at once and never ends on a stuck loader.
Checklist
- One delegated listener for clicks and one for submits, in the shared layout.
- Skip new tabs, modifier keys, downloads, other sites, same-page anchors and file paths.
- Run after page handlers, and respect a click they cancelled (except in frameworks that cancel every link).
- Bar at once; a veil that blocks taps only after a short delay, so fast pages never flash.
- Mark the tapped button busy; keep fetch-based saves busy until the request settles.
- Undo on
pageshow, on visibility return, on Escape, on navigation error, and on a timer. - Respect reduced motion and right-to-left layouts.
- Walk every button on a phone-sized screen before calling it done.
Need this?
Every product GeoTech builds ships with instant tap feedback, skeleton loading and double-submit protection from the first release. If your web app or WebView app feels frozen between taps, we can add the same engine to it without rewriting your pages. Talk to GeoTech.