< Back

How Out-Of-Order Streaming HTML Will Revolutionize The Web

The biggest new feature since AJAX

calendar

Nov 30, 2026

Header for posting How Out-Of-Order Streaming HTML Will Revolutionize The Web
Photo by Valery Sysoev on Unsplash

Did you ever wish you could serve some parts of your HTML earlier or later than others?

Imagine your web app has a large dropdown menu at the top of the page. Since HTML is delivered in a top-to-bottom fashion, the HTML after this menu won’t be available until the HTML for the menu is downloaded and parsed, but the user won’t be able to use the menu until the page becomes interactive. The menu HTML might as well be delivered later so the rest of the page is available sooner.

Or how about a single-page app with a page shell? This shell is delivered in the first request, and then JavaScript is needed to plug in all other HTML.

Wouldn’t it be nice if you could do this in one request and choose the order in which the HTML parts are delivered, regardless of their order in the source document?

Well, now you can! 💪

Out-of-order streaming HTML

There have already been some experiments with out-of-order streaming HTML that use Declarative Shadow DOM and <slot> elements to stream HTML out of order:

<div>
<template shadowrootmode="open">
<header>Header</header>
<main>
<slot name="content"></slot>
</main>
<footer>Footer</footer>
</template>
<div slot="content">
This div will be rendered inside the slot above without JavaScript.
</div>
</div>

In the above example, <slot name=”content”></slot> will be replaced with <div slot=”content”> as soon as it’s available in the browser, without any JavaScript.

This is a very neat feature, but it only works with Shadow DOM.

In Chrome 157, you can now use Declarative Partial Updates that enable web apps to stream HTML into parts of the document, regardless of the order in which it’s delivered by the server.

For example, web apps can now download the most important HTML first, even when this is not at the top of the HTML document.

How it works

Streaming out-of-order HTML is called “patching”. It means you can interleave content for multiple locations in an HTML document in one HTML stream, and the content doesn’t have to be streamed in the order in which it’s located in the document, hence “out-of-order streaming”.

It works by putting processing instructions in an HTML document that function as the insertion points where the content will be streamed into:

<div>
<?marker name="content">
</div>

<template for="content">
<p>Here is the content that will be inserted.</p>
</template>

In the above example, the processing instruction <?marker name=”content”> will be replaced with the contents of the <template>.

The template will look up the processing instruction with a name attribute that corresponds to its for attribute and replace it with its contents.

The above example will end up like this:

<div>
<p>Here is the content that will be inserted.</p>
</div>

In addition to <?marker>, you can also use the <?start> and <?end> markers that enable you to add temporary content that will be displayed until it’s replaced with the contents of the corresponding <template> element:

<div>
<?start name="list">
Loading…
<?end>
</div>

...

<template for="list">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</template>

In this example, “Loading…” is displayed inside the <div> until it’s replaced with the list inside the <template> element.

This would enable you to first stream a skeleton HTML page with a loading screen, and after that you could append the list HTML, which is maybe fetched from an external API that takes longer to load.

Normally, you would first serve the app shell, then fetch the list with the API data in a separate request, and then use JavaScript to insert the list HTML. With patching, you can do everything in a single HTML response without having to use JavaScript to insert the list.

You can even add processing instructions in the templates to enable updates in multiple steps. Imagine that the list in the previous example is loaded in chunks instead of fully in one request. By including processing instructions in the templates, you can now continuously update the list:

<div>
<?start name="list">
Loading…
<?end>
</div>

This results in the following HTML:

<div>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<?marker name="items">
</ul>
</div>

...

<template for="list">
<ul>
<li>Item 1</li>
<?marker name="items">
</ul>
</template>
<template for="items">
<li>Item 2</li>
<li>Item 3</li>
<?marker name="items">
</template>
<template for="items">
<li>Item 4</li>
<?marker name="items">
</template>

This is huuuuge…

…and there’s even more…

Streaming HTML in single-page apps

Single-page apps (SPA) have long been the solution to make web apps feel like real apps, because they only update the changed content when the user navigates to another page, without a full page reload.

The downside of this is that SPAs can’t use the browser’s streaming parser. When a browser loads a web page, it can do so in a streaming fashion. This means that it can already start rendering the page while it’s still downloading; it doesn’t have to wait for the page to be fully loaded before it can start rendering content.

SPAs typically load a skeleton HTML page and then update the content with DOM manipulation using JavaScript. Any content that is inserted into the DOM after the page has been served by the server cannot use the browser’s streaming parser. It has to wait for all content to be ready before it can start to render it when it’s inserted using JavaScript (for example, with innerHTML).

Until now…

New streaming methods

In addition to existing methods like setHTML, setHTMLUnsafe and the innerHTMLand outerHTML setters, this proposal adds streaming methods like streamHTML, streamHTMLUnsafe, streamAppendHTML etc.

This enables SPAs to stream HTML into the insertion points marked by processing instructions using JavaScript. This means that instead of using innerHTML to update content, your SPA can now do this:

const response = await fetch('/path/to/content.html');
const html = await response.text();

const writer = document.body.streamAppendHTMLUnsafe().getWriter();
await writer.write(html);
await writer.close();

Note that in this example, the content is added to the <body> element.

When you use <template> elements and markers, you don’t even need to get a reference to the insertion point with JavaScript anymore. You can just define the insertion point of the SPA content with a marker:

<main id="app">
<section class="page">
<?marker name="content">
</section>
</main>

And then you can simply append the <template> to the bottom of the page:

<template for="content">
<?start name="content">
<p>Homepage content</p>
<?end>
</template>

Since you defined a marker and added this template to the bottom of the page, the browser will now take care of inserting the content in the right place. Also note that this template contains <?start> and <?end> markers, and the resulting HTML will be this:

<main id="app">
<section class="page">
<?start name="content">
<p>Homepage content</p>
<?end>
</section>
</main>

This ensures that the processing instructions are ready for when the user navigates to another page. If each partial contains these processing instructions, you can always just add the page HTML to the bottom of the page, and the browser will then insert it in the right location while replacing the contents of the previous page.

And there’s even more good news…

Cross-browser support is coming soon

Not only can you already use this in Chromium-based browsers from version 157, but the WebKit team (Safari) has announced they will support this and the Firefox team has a positive position on this feature.

This means this feature could be supported in all major browsers soon! 💪

Demo

I created a demo SPA that uses the technique described above to update the page content. It defines markers in the HTML where the page content is to be inserted, and each page partial HTML template contains new markers where the content of the next page is to be inserted. All page templates are simply added to the bottom of the page, and the browser takes care of the rest.

Check out the demo and the source code.

Notice that the demo uses the streamAppendHTMLUnsafe() method to stream the content. The Unsafe variant is required to preserve the <template> element in the HTML that is inserted. Using streamAppendHTML()results in empty HTML and doesn’t work.

Also notice that the streaming methods are required to use templates and markers. When you use non-streaming methods, like appendHTMLUnsafe() for example, the parent of the template when it is parsed is an intermediate document fragment, and the patching happens "in place" inside the fragment instead of in the insertion point indicated by the markers.

The /list route of the demo demonstrates a list that is updated in chunks. The demo just uses setTimeout() to simulate a response that delivers the chunks, but you can probably imagine how this would work in a production scenario where the content is delivered in real chunks.

Also make sure to check out the Chrome developers article and the accompanying demo, which demonstrates the out-of-order streaming very well.

This is a very promising feature that will truly revolutionize how HTML is delivered.

When more browsers support this, you will hear it from me first!


Join my email list Modern Web Weekly, for a weekly update on Progressive Web Apps (PWA), Web Components and new features of the modern web platform, tested and explained in plain English.