Getting Started
Installation and Basic Usage
Installation
BareMetal.js can be used natively without a build step or installed via NPM for bundler environments.
Option 1: Using NPM
# Install via npm
npm install baremetal.js
// In your main entry file
import { BareMetal, loader } from 'baremetal.js';
Option 2: Using CDN
<script type="module">
import { BareMetal, loader } from 'https://cdn.jsdelivr.net/npm/baremetal.js/src/index.min.js';
</script>
The Golden Rule: Loader Requirement
Critical: The BareMetal Router explicitly parses newly fetched HTML pages looking for the loader({...}) function call. If it does not find it, the router assumes the page is not a BareMetal SPA page and will fall back to a full native browser reload!
Even if a page does not have any specific JavaScript modules to load, you must include an empty loader call on every single HTML page you want to participate in the SPA routing.
Example of an empty page setup:
<html>
<head>
<!-- Your shared layout/config -->
<script type="module" src="config.js"></script>
</head>
<body>
<h1>Hello World</h1>
<!-- REQUIRED: Include this on every page -->
<script type="module">
import { loader } from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/baremetal.js';
loader({}); // Signals to BareMetal that this is a valid SPA page
</script>
</body>
</html>