A production vanilla-JS single-page app (no framework, no build)
vanilla-jses-modulesspahash-routertagged-templatesjwtflutter-rewrite
In June 2026 the Hunsley Hills Salon site was rewritten from a ~4,500-line Flutter web app to a hand-written vanilla JavaScript SPA: native ES modules, plain CSS, a hash router, and the same PHP API behind it. Flutter's toolchain and multi-platform abstraction bought nothing for a single web target, and the rewrite gained real DOM, SEO-able text, normal browser behavior, and deploys that are just file copies. This is the structure that worked, at the scale of a small business site with an admin area. For one-file tools see Zero-build web apps (vanilla JS, localStorage, single file).
Structure (site/)
index.htmlshell:<header id="site-header">,<main id="view">,<footer>,<div id="toast-root">; web fonts and the Material Symbols icon font loaded from Google Fonts.css/styles.css: the old Flutter theme ported to CSS custom properties (palette, gradients, shadows, radii) plus component classes.js/config.js: API base URL and external booking URL. Runtime config is edited and redeployed, not injected by a build flag.js/api.js: fetch wrapper (base URL, JWT header, JSON decode, throws anApiError); anupload(path, formData)variant that does not set Content-Type so the browser adds the multipart boundary.js/auth.js: session in localStorage (token + user),restore()verifies viaGET /auth/me, emits anauth-changeevent.js/dom.js:esc, anhtmltagged template that escapes interpolations by default (wrap trusted markup inraw()),el, delegatedonClick, money/date formatters.js/router.js: hash router (#/services) with a route table and guards (/accountneeds auth,/admin/*needs admin, else redirect). Views are lazyimport()ed and each exportsrender(root, { query, navigate }). Dispatchesroute-change.js/components/: header/footer chrome that re-renders on route and auth changes; shared UI (section headings, loading/empty/error states, toast, modal and confirm dialog, IntersectionObserver reveals, requestAnimationFrame count-up counters); an image picker.js/views/: public pages plusadmin/*CRUD views built on modals.
A hash router needs no server rewrite rules; any static host works.
Gotchas
- Inline
displaybeats media queries. The header setstyle="display:flex"on elements amax-width: 900pxmedia query was meant to hide, so the desktop nav never collapsed on phones and the hamburger never appeared. Put responsivedisplayin classes only, never inline on an element a media query toggles.body { overflow-x: hidden }is a cheap guard. - Import shadowing and the TDZ. A view that does
import { content } from './content.js'and also declaresconst content = ...locally throws "Cannot access 'content' before initialization". Rename the local. - New tabs only open from a synchronous click.
window.open(url, '_blank', 'noopener')inside the click handler works. Anything async between the click and the open (anawait, Flutter'surl_launcher) breaks the user-activation chain and the popup blocker eats it; the old Flutter app had to fall back to same-tab navigation for the booking link. - Naive datetimes. The API returns SQL datetimes without a zone;
new Date(s)parses them as local time. Decide the convention explicitly. - Tinting a raster logo. CSS
filtercannot recolor a PNG to an exact brand color; use it as amask-imageover a colored background (the CSS equivalent of Flutter'sColorFilter.srcIn). - A
<select>cannot render icon-font glyphs in its option list. An icon picker has to be a grid of real buttons backed by a hidden input. - Empty CMS values: remove the whole block (icon and label too) rather than rendering a label with nothing after it.
Image loading on mobile
- Hero image
fetchpriority="high"(never lazy-load the LCP element); gallery and product imagesloading="lazy" decoding="async". - A shimmer placeholder class on the container, removed by the image's
onload(andonerror). - None of that helps if the images are 3 MB phone photos; the real fix was resizing on upload (Resizing uploaded photos on the server (PHP GD)).
Testing without a framework
node --check file.jsfor syntax.- A temporary
test-smoke.htmlthat imports the ES modules directly, stubs state through exported setters, calls a view'srender(), and writes the results intodocument.title; run it withgoogle-chrome --headless=new --dump-domand grep the<title>. Delete it before deploying. Details in Headless Chrome testing gotchas.
See also
- Zero-build web apps (vanilla JS, localStorage, single file)
- A lightweight CMS for a small business site
- Resizing uploaded photos on the server (PHP GD)
- Headless Chrome testing gotchas
- CSS layout gotchas on phones
Linked from
- A lightweight CMS for a small business site
- CSS layout gotchas on phones
- Flutter web (renderers, SEO, performance, when not to use it)
- Offline-first browser tools (module workers, precache lists, no build step)
- Personal finance dashboards: bank aggregation and subscription detection
- Resizing uploaded photos on the server (PHP GD)
- umlol, a programming language whose source is a flowchart
- Where-to-stream lookups (TMDB watch providers and the Streaming Availability API)