iframes
Each team's app is a separate page shown in a frame. Nothing leaks in or out, and nothing is shared, including the cost.
How it works
- A frame per app. The shell renders an iframe for each team's page.
- Separate document. Each frame loads its own HTML, JavaScript and CSS from the team's server, as its own browsing context.
- Again for team B. Team B's frame does the same, with its own document and resources.
- postMessage. Frames talk to the shell with postMessage, naming the exact target origin and checking the sender's origin.
Try it
Style isolation
Team A ships .button { background: orange; border-radius: 0 } and body { font-family: Georgia, serif }, and Team B sets no font of its own. Without isolation, both rules are global: Team B's Pay now button turns orange and its text changes font. With CSS Modules, the class is renamed to something like .button_x7f2a, so Team B's button is safe, but body is a tag selector and stays global, so the font still changes. With Shadow DOM, selectors can't cross the shadow root, so the button is safe, but inherited properties such as the font still pass from the host into the shadow tree unless Team B resets them. With an iframe, Team B runs in its own document: neither rule reaches it, and nothing is shared either, at the cost of a whole extra page load.
Pros
- Strongest isolation: styles, globals and uncaught errors stay inside the frame.
- Each frame can use any technology and version.
- The simplest way to embed an app you cannot change.
Cons
- Every frame costs memory and loads its own resources.
- Routing, history, deep links and resizing have to be synced by hand.
- Each frame needs a title, and moving between frames is harder for screen reader users.
Best when
- Embedding third-party or untrusted content, together with the sandbox attribute.
- Legacy apps you cannot change.
- Internal tools where load time matters less.
Avoid when
- Public, SEO-critical pages.
- Tightly integrated interfaces that share state.
- Tight mobile performance budgets.
In code
<!-- shell.html -->
<iframe src="https://team-b.example.com/cart"
title="Cart" loading="lazy"></iframe>
<script>
// Accept messages only from team B's exact origin
window.addEventListener("message", (event) => {
if (event.origin !== "https://team-b.example.com") return;
if (event.data?.type === "cart:updated") updateCartBadge(event.data.count);
});
</script>
<!-- team-b.example.com/cart, inside the frame -->
<script>
// Name the exact target origin, never "*"
window.parent.postMessage(
{ type: "cart:updated", count: 2 },
"https://shop.example.com"
);
</script><!-- shell.html -->
<iframe src="https://team-b.example.com/cart"
title="Cart" loading="lazy"></iframe>
<script>
// Accept messages only from team B's exact origin
window.addEventListener("message", (event) => {
if (event.origin !== "https://team-b.example.com") return;
if (event.data?.type === "cart:updated") updateCartBadge(event.data.count);
});
</script>
<!-- team-b.example.com/cart, inside the frame -->
<script>
// Name the exact target origin, never "*"
window.parent.postMessage(
{ type: "cart:updated", count: 2 },
"https://shop.example.com"
);
</script>Tooling and ecosystem
iframes are old, but that is also why they are well proven. Natalia Venditto still counts them as a valid choice when encapsulation is the priority, because a frame comes with a full sandbox out of the box, and notes they can be combined with other techniques such as web components.
There is nothing to install: <iframe> and postMessage are standard browser features documented on MDN. Two details matter in practice. Give every frame a title that describes its content, so screen reader users know what it holds without entering it. When frames send messages, always pass an exact target origin instead of *, and check event.origin in the receiving window. For untrusted content, the sandbox attribute restricts what a frame can do; MDN warns that combining allow-scripts and allow-same-origin for same-origin content removes that protection.