Base URLs as a Deterministic Primitive
Once you formalize base URLs, routing, workers, caching, offline behavior, and portability stop being emergent side effects and become mechanically predictable outcomes.
Research Synthesis
Across browser specifications (HTML, Fetch, Service Workers, ES Modules), the URL is the only globally shared identity object. Requests, module graphs, caches, security boundaries, and execution scopes all resolve through URL normalization and origin comparison.
Systems become fragile when different subsystems are allowed to invent their own implicit base. They become deterministic when a single base is formalized and everything else derives from it.
Failure Mode Analysis
Implicit Bases Create Split Reality
fetch("../api/data.json")
import("./utils/math.js")
new Worker("worker.js")
Each line above may resolve against a different base: document URL, module URL, or execution context. The browser is compliant. The system is incoherent.
Formalization Pattern
Single Source of Spatial Truth
export const BASE =
new URL("/", location.origin).href;
export const api = p =>
new URL(p, BASE).href;
This pattern converts relative intent into absolute identity. Every subsystem consumes the same coordinate space.
Deterministic Effects by Subsystem
Routing
Reloads, deep links, history navigation, and bookmarks all resolve identically because path resolution is absolute, not contextual.
Workers
Worker scope, module imports, and cache access become statically predictable. No phantom imports, no cross-scope leakage.
Service Workers
Cache keys normalize. Offline rules apply cleanly. Updates are atomic instead of probabilistic.
Offline
Offline becomes a binary condition (network present or not), not a cascade of partial failures.
Portability
The application survives relocation: local files, localhost, CDNs, static hosts, air‑gapped systems.
The Deeper Insight
Base URLs are not a convenience layer. They are a deterministic primitive— on par with clocks in distributed systems or memory models in programming languages.
When the base is formalized, the browser stops improvising. The system becomes something you can reason about, prove properties about, and trust under pressure.
Operational Rule
If a subsystem constructs a URL, it must do so from the same base as every other subsystem.
Violating this rule does not cause immediate failure. It causes delayed, environment-dependent failure— the most expensive kind.
Comments
Post a Comment