Web Fragments (v0.8.2) is a framework-agnostic micro-frontends architecture that isolates each fragment's JavaScript execution in a separate context while sharing the same DOM. Developed by Cloudflare, it supports client and server-side rendering, soft navigation, custom CSP, and SSR piercing. Released regularly (monthly patches/minors), it is production-tested at Cloudflare. Unlike other solutions, it offers true JS context isolation via a custom gateway and client-side virtualization, enabling incremental migration from monolithic apps.
npm install web-fragmentsVerified import paths — ran on the pinned version, not inferred.
Shows basic server-side FragmentGateway and client-side FragmentClient setup with ESM imports.
Use import syntax instead of require().
Update fragment registration to pass URL or fetch function.
Replace fetch option with gateway route handler.
Set Content-Security-Policy in FragmentConfig#iframeHeaders.
Attach event listeners to the fragment element instead of document.body.
Use polyfills for custom elements and shadow DOM if needed.
Replace require with import: import { FragmentClient } from 'web-fragments/client'.Use gateway.route(req, ctx) inside Cloudflare Workers fetch handler instead of 'on'.
Use a modern browser or add a shadow DOM polyfill.