BareMetal.js
Categorie
Description
A lightweight, dependency-free Vanilla JavaScript SPA engine prioritizing extreme performance, native browser features, and explicit lifecycle management.
Overview
BareMetal.js is designed to bring Single Page Application (SPA) functionality to vanilla HTML/JS projects without the overhead of heavy frameworks or build steps. It intercepts navigations to provide instantaneous page transitions while giving developers precise control over module lifecycles and state.
Key Features
Hover Pre-fetching (0ms Latency)
BareMetal anticipates user actions. When a user hovers over an internal link, the engine instantly fetches the HTML in the background. By the time they click, the page is already cached, resulting in instantaneous, zero-latency transitions.
Auto-Request Cancellation
If a user is frantically clicking links, BareMetal won’t clog up their network. The Router automatically utilizes the AbortController API to cancel any pending fetch requests as soon as a new navigation is triggered, saving bandwidth and preventing race conditions.
Smart Module Keep-Alive
Share state and complex UI modules (like persistent sidebars or floating media players) across page transitions without destroying them. Native <video> and <audio> tags are preserved and re-injected into the new DOM layout without interrupting playback!
Component Lazy Loading
Load heavy widgets only when they scroll into view! The Loader supports an IntersectionObserver API out of the box. Just pass a lazy CSS selector to the loader({ widget: { path: './widget.js', lazy: '#widget' } }) and it defers downloading and execution until the user actually sees it.
State Hydration (F5 Resilience)
Never lose state on a hard reload again. If enabled, BareMetal automatically serializes the stateManager to sessionStorage in real-time. If the user hits F5, the engine instantly hydrates the state and bounces right back to where they were!
DOM Virtualization Helper
Rendering 10,000 table rows? BareMetal exposes a Virtualizer class that recycles DOM nodes to render massive lists with zero jank. When enabled globally, the engine automatically injects the virtualize helper directly into your module’s mount context.
Scroll Memory & Programmatic Back
Maintains a persistent history stack, restoring your exact scroll depth instantly when navigating backward.
Reactive State Management
Includes a built-in publish/subscribe Signals pattern, preventing race conditions and keeping your UI synced.
Custom Page Transitions
Build and integrate your own loading animations and transition effects hooking into the routing lifecycle.
Handles navigation failures gracefully with configurable fallback UIs.
Auto-Wrap Module Loader
Can automatically wrap simple scripts into conformant lifecycle modules to prevent errors.




